Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

xtk.session.Write for memo element

Darren_Bowers
Community Advisor
Community Advisor

I have a temporary schema that has a bunch of normal attributes and a memo element. When I use xtk.session.Write with an XML object, the attributes update fine, but the memo element (IrMessage) is blank. Any idea how to template in an XML element in the JS?

 

 

 

<!-- Key Fields -->
    <attribute label="Workflow Id" length="32" name="workflowId" notNull="true" required="true"
               type="string"/>
    <attribute label="Service Order Id" length="12" name="serviceOrderId" notNull="true"
               required="true" type="string"/>
    <attribute label="Switch Document Id" length="20" name="switchDocumentId" notNull="true"
               required="true" type="string"/>
    
    <!-- data fields -->
    <attribute label="EDM Link" length="256" name="edmLink" type="string"/>
    <attribute label="bit.ly code" length="12" name="bitly" type="string"/>

    <element label="IR Message" name="IrMessage" type="memo"/>
    <attribute label="IR Description" name="IrDescription" type="string"/>
writeRecord: function ( data ) {
   
      try{ 
        xtk.session.Write(
          <TempData xtkschema="ori:TempData" 
            _operation="insert"
            _key="@switchDocumentId,@serviceOrderId,@workflowId"
            switchDocumentId={data.switchDocumentId}
            serviceOrderId={data.serviceOrderId}
            workflowId={vars.thisWorkflowId}
            edmLink={data.edmLink}  
            bitly={data.bitly} 
            IrDescription = {data.IrDescription}>
            <IrMessage>{data.IrMessage}</IrMessage>
          </TempData>);
      } catch (e) {
        logError("Something bad happened in writeRecord: " + e);
      }
}

 

 

 

 

 

1 Accepted Solution
Darren_Bowers
Correct answer by
Community Advisor
Community Advisor

Managed to do it via sqlExec, but interested to know why the above xtk.session.Write method wouldn't work

try {
  sqlExec("insert into oritempdata (sbitly,sedmLink,sIrDescription,mIrMessage,sswitchDocumentId,sserviceOrderId,sworkflowId) values ('" + data.bitly + "','" + data.edmLink + "','" + data.IrDescription + "','" + data.IrMessage + "','" + data.switchDocumentId + "','" + data.serviceOrderId + "','" + vars.thisWorkflowId + "');");
} catch (e) {
   logError("Something bad happened in writeRecord: " + e);
}

View solution in original post

3 Replies
Darren_Bowers
Correct answer by
Community Advisor
Community Advisor

Managed to do it via sqlExec, but interested to know why the above xtk.session.Write method wouldn't work

try {
  sqlExec("insert into oritempdata (sbitly,sedmLink,sIrDescription,mIrMessage,sswitchDocumentId,sserviceOrderId,sworkflowId) values ('" + data.bitly + "','" + data.edmLink + "','" + data.IrDescription + "','" + data.IrMessage + "','" + data.switchDocumentId + "','" + data.serviceOrderId + "','" + vars.thisWorkflowId + "');");
} catch (e) {
   logError("Something bad happened in writeRecord: " + e);
}

View solution in original post

wodnicki
Community Advisor
Community Advisor

Try xtk.persist.Write(). The sqlExec() call needs special access right and is not as safe/user-friendly- cf your example code where there aren't bind variables or even input escape, so a ' in IrDescription will crash the script.

Darren_Bowers
Community Advisor
Community Advisor
Thanks for the tip - do you have any examples of how to use xtk.persist.Write() with a memo field? As you can see above I couldnt get the xtk.session.Write() to work with the memo field so had to hack the sqlExec() together as a workaround