Extracting data from a checklist

Paolo Manfrin

Assuming that you have a specific checklist and you want to extract only selected data the attached pdf gives you an overview how to use the coresuite framework components in order to extract data from a checklist.


In this sample we will use a minimal checklist in order to make it easier to understand.


 


In this checklist we want to track which serial number has been replaced.



private static void ExtractData(SwissAddonFramework.UI.FunctionButton.FunctionButtonEvent pVal)
{
string serviceCallId = TextEdit.GetFromUID(pVal.Form, "12").Value;
string item = TextEdit.GetFromUID(pVal.Form, "33").Value;
SwissAddonFramework.Utils.CheckList.CheckListContainer container = new SwissAddonFramework.Utils.CheckList.CheckListContainer("191", serviceCallId);
var checkListArray = container.CheckListArray;
var checklistInstance = checkListArray[0];

foreach (string language in checklistInstance.Instance.GetValues().Keys)
{
string instanceId = checklistInstance.Instance.InstanceIdentifier;
// before inserting check if this instance has been already extracted
int indexCounter = Convert.ToInt32(SwissAddonFramework.B1Connector.GetB1Connector().ExecuteScalar("SELECT COUNT([U_InstanceID]) from [@SNREPLACEMENT] WHERE U_InstanceID = '" + instanceId + "'"));

if (indexCounter > 0)
break;

// add the current instance
XmlDocument content = checklistInstance.Instance.GetValues()[language];
string oldNS = content.SelectSingleNode("/values/string[@key='Chapter_1.SN_OLD.value']").InnerText;
string newSN = content.SelectSingleNode("/values/string[@key='Chapter_1.SN_NEW.value']").InnerText;
string remarks = content.SelectSingleNode("/values/string[@key='Chapter_1.NOTE.value']").InnerText;

string nextId = SwissAddonFramework.B1Connector.GetB1Connector().ExecuteQueryScalar("select RIGHT('00000000' + CAST(COUNT(Code)+1 AS nvarchar(8)), 8) from [@SNREPLACEMENT]").ToString();
string queryUpdate = @"INSERT INTO [dbo].[@SNREPLACEMENT]
([Code]
,[Name]
,[U_CallID]
,[U_OldSN]
,[U_NewSN]
,[U_Remarks]
,[U_ITEM]
,[U_InstanceID])
VALUES
(@Code
,@Name
,@callID
,@oldSN
,@newSN
,@remarks
,@item
,@instanceID)";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = queryUpdate;
cmd.Parameters.AddWithValue("@Code", nextId);
cmd.Parameters.AddWithValue("@Name", nextId);
cmd.Parameters.AddWithValue("@callID", Convert.ToInt32(serviceCallId));
cmd.Parameters.AddWithValue("@oldSN", oldNS);
cmd.Parameters.AddWithValue("@newSN", newSN);
cmd.Parameters.AddWithValue("@remarks", remarks);
cmd.Parameters.AddWithValue("@item", item);
cmd.Parameters.AddWithValue("@instanceID", instanceId);
SwissAddonFramework.B1Connector.GetB1Connector().ExecuteNonQuery(cmd);
}

}

A step by step description is provided in the attached pdf



0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post