Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 07, 2013 @ 19:22
    Fuji Kusaka
    0

    Custom Workflow to retrieve ID from DB

    Hi Guys,

    I have finally managed to create a new custom workflow in contour so as to update a hidden field in one of my request form.

    This request form will have an ID which will increment each time a user submit a form. However this ID is only in the DB and not in contour. With the new Custom Workflow the idea is to update this Hidden Field so that when the admin go to the View Entries in contour he sees the ID related to the form.

    What am not sure is how do i retrieve this ID from DB in my custom workflow ? How do i make an SQL Connection to retrieve this value ?

    My workflow applies when the form has been approved here.

    Any suggestion please ??

  • Comment author was deleted

    Oct 08, 2013 @ 10:32

    Hey Fuji, you can just make an sql connection in the way you prefer :), are you on Umbraco 4 or 6?

  • Comment author was deleted

    Oct 08, 2013 @ 10:55

    Depending on the version I can share a snippet of code :)

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 08, 2013 @ 11:05
    Fuji Kusaka
    0

    Am on V 4 using Contour 3.0.17

  • Comment author was deleted

    Oct 08, 2013 @ 11:09

    In that case you can use the old datalayer

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 08, 2013 @ 11:34
    Fuji Kusaka
    0

    Will something like this work ?

    SqlConnection vlhConn = new SqlConnection();
    String sql = string.Format("SELECT * FROM [uFRecords] ", "Some Value")
  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 08, 2013 @ 14:26
    Fuji Kusaka
    0

    Not sure where am going with this but am completely lost here, had a look Umbraco.Forms.Core.Providers

     

     public class UpdateId : Umbraco.Forms.Core.WorkflowType
        {
            [Umbraco.Forms.Core.Attributes.Setting("Connection String", description = "SQL Connection String", prevalues = "Provider=SQLNCLI10;Server=tabata;Database=umbraco_vresorts;Uid=sql_eservices; Pwd=slash!0;", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
            public string Connection { get; set; }

            [Umbraco.Forms.Core.Attributes.Setting("Document ID", description = "Node the log entry belongs to", control = "Umbraco.Forms.Core.FieldSetting.Pickers.Content")]
            public string document { get; set; }

            [Umbraco.Forms.Core.Attributes.Setting("AutoID", description = "Update the ID here", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string AutoID { get; set; } 
            public UpdateId()
            {
                this.Name = "Update AutoID Field In Contour";
                this.Id = new Guid("44f913a6-6f5e-4866-8b35-64688d1b7c35"); //   4182f9da-d0e4-4602-9874-5cbec3a5d462
                this.Description = "This workflow will update the AutoID";
            }
          public override List<Exception> ValidateSettings()        {
                List<Exception> exceptions = new List<Exception>();
                if (string.IsNullOrEmpty(LogHeader))
                    exceptions.Add(new Exception("'Header look up field' setting not fille out'"));
                 if (string.IsNullOrEmpty(document))
                    exceptions.Add(new Exception("'Document is empty'"));
          return exceptions;
            }

          public override Umbraco.Forms.Core.Enums.WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
            {
               // SqlConnection sqlConn = new SqlConnection("umbracoDbDSN");
                //string sql = string.Format("SELECT * FROM [uFRecords]");

                 return Umbraco.Forms.Core.Enums.WorkflowExecutionStatus.Completed;
          }
        }

    //fuji

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 08, 2013 @ 16:54
    Fuji Kusaka
    0

    Any help on this please ?

  • Comment author was deleted

    Oct 08, 2013 @ 18:01

    the prevalues property is used for dropdowns/radiobutton lists try default value instead but yeah SqlConnection is a good start

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 09, 2013 @ 07:29
    Fuji Kusaka
    0

    Thanks Tim. I tried removing Prevalues but cant make use of Dafault its giving me an error.

    I tried that instead but how to i get to view the Ids

    public override Umbraco.Forms.Core.Enums.WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
           {
    SqlConnection sqlConn = new SqlConnection("Provider=SQLNCLI10;Server=tba;Database=umbraco_vrs;Uid=sql_es; Pwd=slash!0;");
                try
                {
                    SqlDataReader myReader = null;
                    SqlCommand myCommand = new SqlCommand("SELECT * From [uFRecords]");
                    myReader = myCommand.ExecuteReader();
                    while (myReader.Read())
                    {
                        Console.WriteLine(myReader["AutoID"].ToString());
                    }
                }
                catch (Exception t){
                   Console.WriteLine(t.ToString());
               }
                //string sql = string.Format("SELECT * FROM [uFRecords]");
                return Umbraco.Forms.Core.Enums.WorkflowExecutionStatus.Completed;
            }
  • denisedelbando 141 posts 339 karma points
    Nov 08, 2013 @ 19:57
    denisedelbando
    0

    was this fixed? I am doing something similar but i am using EF instead to connect to the database. And I am inserting records not selecting. this is something i need to do though. Retrieving the latest record executed. Any luck?

Please Sign in or register to post replies

Write your reply to:

Draft