Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andres Cano 22 posts 42 karma points
    May 03, 2011 @ 17:10
    Andres Cano
    0

    Trigger Approved Workflow using .NET User Control - Corrected

    Hi im trying to setup a button in a form named "Click to Approved" to trigger the approved workflow in the back end of umbraco of that record id, for this task i created a form with an editable macro, and im sending the record.id at the end of the form link with ?recordGuid= follow by the record id, taking it using the braket syntax trought the send email.

    in the Button User Control i have been using some info related founded in this posts

     

     

    but i just cant get it work

    this is the code of my Button "Click to Approved" User Control

     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Services;
    using Umbraco.Forms.Data;
    using Umbraco.Forms.Data.Storage;
    using umbraco.BusinessLogic;
    
    namespace UmbracoContourExtendAC
    {
        public partial class ApprovedButton : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                RecordStorage rs = new RecordStorage();
    
                Record record = rs.GetRecord(new Guid("7ba0a2b0-86d7-4ae0-ad57-d98cc1da5b92"));
    
                RecordService s = new RecordService(record);
    
                if (s != null)
                    s.Approve();
    
                s.Dispose();
    
            }
        }
    
    }

     

    any help will be great, i have been thinking so much in this that is almost driving me crazy...

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 03, 2011 @ 18:02
    Tom Fulton
    0

    Hi,

    I'm using pretty much the exact same code for the same thing (but in a /base method) and it's working fine.  What exactly is the problem?  Are you getting any errors?

    -Tom

  • Andres Cano 22 posts 42 karma points
    May 03, 2011 @ 18:24
    Andres Cano
    0

    Well basically im getting a 

    Runtime Errorr when i debug the user control, creating the .dll and put it on the bin folder,

    but the User control Works fine when i comment this part of the code

     if (s != null)
                    s
    .Approve();

                s
    .Dispose();

    and the page dont crash and the button "Click to Approved" is rendered, but otherwise without comment that part everything stop working  

    but the User control Works fine when i comment this part of the code

     

     if (s != null)
                    s
    .Approve();

                s
    .Dispose();

    and the page dont crash and the button "Click to Approved" is rendered, but otherwise without comment that part everything stop working  

     thanks a lot for your help I really appreciate it!

  • Andres Cano 22 posts 42 karma points
    May 03, 2011 @ 18:26
    Andres Cano
    0

    sorry for the double post, i was trying to copy the code to show you

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 03, 2011 @ 19:18
    Tom Fulton
    0

    Hi,

    The only thing I can think of off the top of my head is maybe the GUID is incorrect? Or the record is already approved?

    You should also try to get a more detailed error, maybe by debugging your usercontrol in Visual Studio, making sure you have custom errors set to Off, and maybe checking the umbracoLog table.  "Runtime error" isn't too helpful :)

    -Tom

  • Andres Cano 22 posts 42 karma points
    May 03, 2011 @ 20:37
    Andres Cano
    0

    Hi Tom, i check all that but no luck so far, when i debug the user control in visual, everything is fine, maybe i have a loss step in all this process im going to explan you what i have done until now.

    the problem: create a button outside the backend of umbraco to approved a form into the same page of the form.

    solution:

    1. i create a template for a page and insert a macro that render the form with allow editing, 

    2. i create a macro for a custom button that is going to use a user control to render this button,

    this is the code for the template:

     

    <asp:Content ContentPlaceHolderID="ggblank" runat="server">
      
      <br/><br/>
      
      <umbraco:Macro Alias="ApprovedButton" runat="server"></umbraco:Macro>
      
      
        <umbraco:Macro FormGuid="a30ce693-1201-456d-9f67-7c2611eb9786" 
                       AllowEditing="1"
                       Alias="umbracoContour.RenderForm" 
                       runat="server">
        </umbraco:Macro>

    </asp:Content>   

     

    the code for the user control is

     

    <asp:Button ID="button1" runat="server" Text="Click to Approved" />

     

    now the .cs code of the user control

     

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Services;
    using Umbraco.Forms.Data;
    using Umbraco.Forms.Data.Storage;
    using umbraco.BusinessLogic;

    namespace UmbracoContourExtendAC
    {
       
    public partial class ApprovedButton : System.Web.UI.UserControl
       
    {
           
    protected void Page_Load(object sender, EventArgs e)
           
    {
               
    RecordStorage rs = new RecordStorage();

               
    Record record = rs.GetRecord(new Guid("7ba0a2b0-86d7-4ae0-ad57-d98cc1da5b92"));

               
    RecordService s = new RecordService(record);

               
    if (s != null)
                    s
    .Approve();

                s
    .Dispose();

           
    }
       
    }
    }  

     

     

    in the other side i added to the workflow when the form is submitted "send email" and in the body of the email i ad the {record.id} at the end of the link of the rendered form.

    ex. <link to the form>?recordGuid={record.id}

    now the ideal thing will be, when the person in charge recieved the email just click on the link of the email received, and this will render athe form, with the info of the record, and in the top part there will be a button named "Click to Approved", but what is happening is

    1. when i debug the user control in visual everything is fine, after copy the .dll and the user control, and tried to retrieve the page there is a crash on the .net page and the message is Server Error in '/' Application, Runtime Error in

    " <!-- Web.Config Configuration File -->

    <configuration>

        <system.web>

            <customErrors mode="Off"/>

        </system.web>

    </configuration> "

    2. when i debug the user control in visual comment the part of the code:

     

       if (s != null)
                    s
    .Approve();

                s
    .Dispose();

     

    and copy the .dll and the user control to the bin and user controls folder, and tring to retrieve the web page there is no crash, and the button is rendered well, but of course there is no functionality at all.

     

    i check this thing:

    GUID is ok

    Debug in Visual  is ok

    and i dont have webcongif file to put the custom errors off, i deleted i only have the properties, references, and the user control file in the visual project, but the debug is okey with only that files.

    i dont know if i just forget one step or something, again, thanks a lot for your help! i hope all this info can give you and idea.

  • Andres Cano 22 posts 42 karma points
    May 03, 2011 @ 20:45
    Andres Cano
    0

    ohh i just see this error if i access the site in my server side:

     The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UFRecords_UFForms". The conflict occurred in database "intranet", table "dbo.UFForms", column 'Id'.
    The statement has been terminated. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UFRecords_UFForms". The conflict occurred in database "intranet", table "dbo.UFForms", column 'Id'.
    The statement has been terminated.
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
    
    Stack Trace: 
    
    
    [SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UFRecords_UFForms". The conflict occurred in database "intranet", table "dbo.UFForms", column 'Id'.
    The statement has been terminated.]
       System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
       System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +215
       System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987
       System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
       System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +178
       System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
       Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters) +56
       Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters) +83
       umbraco.DataLayer.SqlHelpers.SqlServer.SqlServerHelper.ExecuteNonQuery(String commandText, SqlParameter[] parameters) +21
       umbraco.DataLayer.SqlHelper`1.ExecuteNonQuery(String commandText, IParameter[] parameters) +85
    
    [SqlHelperException: Umbraco Exception (DataLayer): SQL helper exception in ExecuteNonQuery]
       umbraco.DataLayer.SqlHelper`1.ExecuteNonQuery(String commandText, IParameter[] parameters) +140
       Umbraco.Forms.Data.Storage.RecordStorage.InsertRecord(Record record, Form form) +763
       Umbraco.Forms.Core.Services.RecordService.‘() +192
       Umbraco.Forms.Core.Services.RecordService.Approve() +89
       UmbracoContourExtendAC.ApprovedButton.Page_Load(Object sender, EventArgs e) +221
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +91
       System.Web.UI.Control.LoadRecursive() +74
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Control.LoadRecursive() +146
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
     

    thanks for your help Tom!

     

  • Bipin Kataria 29 posts 60 karma points
    Jul 15, 2017 @ 03:08
    Bipin Kataria
    0

    Does anyone know the fix for error: The INSERT statement conflicted with the FOREIGN KEY constraint "FKUFRecordsUFForms". The conflict occurred in database "intranet", table "dbo.UFForms", column 'Id'. The statement has been terminated. ?

    I am trying to delete the record from CMS Contour. but getting error with the page call: http://website.com/umbraco/plugins/umbracoContour/webservices/recordActions.aspx?form=11df48d9-23b0-4ed9-9eaa-0f3bc181c744&record=cae52214-6d77-4165-82e5-d2b4e1486dbc&action=cb126b76-9011-11df-a4ee-0800200c9a66&_=1500087606989

  • Bipin Kataria 29 posts 60 karma points
    Jul 15, 2017 @ 04:24
    Bipin Kataria
    0

    Please ignore this request. Its issue with Contour. When you delete the record, it automatically does not refresh the screen, but actually it has physically deleted the record. So, user tries to delete the same record again, but actually this time record is not there in database and you see this error / exception.

Please Sign in or register to post replies

Write your reply to:

Draft