Highlighted
Micro Focus Expert
Micro Focus Expert
57 views

(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");

pmreset.setRecord(backupstring);

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.

Labels (1)
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.