(SM) Support Tip: Tailoring: How to backup a record in JavaScript and restore it?

Service Manager runs complex operations like incident updates that aside updating the probsummary record (storing incident contents) also update many other records like slactive, Approval, etc. Unlike database transaction in RDBMS however these operations cannot be rolled back.

This means for example that when updating an incident, from the moment a user action is started to be processed until the actual saving of a probsummary record all modifications of other database records are persistent, even when the saving of the probsummary record fails. This includes: The processing of the Process record, the called RAD applications, and the BEFORE-UPDATE/ADD-triggers.

Certainly the best option here is a bug free implementation serializing concurrent accesses to the record by locking mechanism. Sometimes, however, this is hard to achieve.

Alternatively records can be backed up in Process record before the call of the RAD application to perform the main record update, so in situation of error, the original record can be restored.

The following JavaScript snippet shows how to do that (exemplary on a record of “pmstatus” dbdict, as it has few fields only):


// get backup

var pmback = new SCFile("pmstatus");

var rc = pmback.doSelect("true");

var backupstring = pmback.getXML().toXMLString();


print("pmback: " backupstring)



// modify record

var pmnow = new SCFile("pmstatus");

rc = pmnow.doSelect("true");

pmnow["sort.order"] ;

rc = pmnow.doUpdate();


print("pmnow: " pmnow.getXML().toXMLString());



// restore from backup


var pmreset = new SCFile("pmstatus");

var rc = pmreset.doSelect("true");


rc = pmreset.doUpdate();


print("pmreset: " pmreset.getXML().toXMLString());



When executed, the messages will show this (latest message on top):


pmreset: <model name="pmstatus" query="true"><keys><name sctype="string">#NULL#</name></keys><instance recordid="#NULL#" uniquequery="name=&quot;#NULL#&quot;"><

name type="string">#NULL#</name><sort.order type="decimal">9</sort.order><sysmodcount type="decimal">15</sysmodcount><sysmoduser type="string">falcon</sysmodu

ser><sysmodtime type="dateTime">07/15/16 14:27:46</sysmodtime></instance></model>


pmnow: <model name="pmstatus" query="true"><keys><name sctype="string">#NULL#</name></keys><instance recordid="#NULL#" uniquequery="name=&quot;#NULL#&quot;"><name type="string">#NULL#</name><sort.order type="decimal">10</sort.order><sysmodcount type="decimal">14</sysmodcount><sysmoduser type="string">falcon</sysmodus

er><sysmodtime type="dateTime">07/15/16 14:27:46</sysmodtime></instance></model>


pmback: <model name="pmstatus" query="true"><keys><name sctype="string">#NULL#</name></keys><instance recordid="#NULL#" uniquequery="name=&quot;#NULL#&quot;"><n

ame type="string">#NULL#</name><sort.order type="decimal">9</sort.order><sysmodcount type="decimal">13</sysmodcount><sysmoduser type="string">falcon</sysmodus

er><sysmodtime type="dateTime">07/15/16 14:20:39</sysmodtime></instance></model>


So all fields in record will be restored by backup with exception of the binary controlled sysmod* fields.