Highlighted
PM Thompson Outstanding Contributor.
Outstanding Contributor.
413 views

Modscript: How do I detect the difference between new ProjectBasedRecord being submitted & one previously submitted?

Jump to solution
Assume a function like:
def Import_PDF_Data(pbr_Item , str_Fname) {

...
}
It may be passed a newly created Project Based Record item:
var pbr = Ext.CreateProjectBasedRecord( n_My_Primary_TableID ) ;

Import_PDF_Data(pbr , "... some path ...") ;
or it may be passed and item, possibly the current item, which was previously submitted.
Import_PDF_Data(Shell.Item , "... some path ...") ;


Is it possible for the function to quickly & easily detect the difference between the newly instantiated PBR and one that had been previously submitted?? I could check for previous transitions in the ChangeActions table, but that doesn't seem real speedy.

Fallback is to add a flag to the function's params that indicates "new item" / "one that's been around the block".
0 Likes
1 Solution

Accepted Solutions
PM Thompson Outstanding Contributor.
Outstanding Contributor.

Re: Modscript: How do I detect the difference between new ProjectBasedRecord being submitted & one previously submitted?

Jump to solution
In a SUBMIT transition, Shell.Item will have a valid TS_ID and TS_ISSUEID. TS_UUID will be blank. In the newly created database record for the item, TS_ID will be 0 and TS_ISSUEID and TS_UUID will be blank.

To read the DB record I create an AppRecord and read the Record ID from Shell.Item.GetId, then use GetFieldValue("issueid") to read TS_ISSUEID, GetId to read TS_ID and GetUUID to read TS_UUID. By using my own AppRecord, I avoid the caching and value initialization done by SBM for Shell.Item.

Note that you can't use the GetFieldValue() function to read TS_ID or TS_UUID -- you have to used the dedicated functions GetId and GetUUID:

var arec_Db = Ext.AppRecord( Shell.Item.GetRecTableId ) ;

var n_Id = Shell.Item.GetId ;
var str_IssueId = "" ;
var str_UUID="" ;

arec_Db.Read(n_Id);

n_Id = arec_Db.GetId ;
str_IssueId = arec_Db.GetFieldValue("issueid") ;
str_UUID = arec_Db.GetUUID ;


return (n_Id==0 && str_IssueId.size==0 && str_UUID.size==0) ;

View solution in original post

3 Replies
PM Thompson Outstanding Contributor.
Outstanding Contributor.

Re: Modscript: How do I detect the difference between new ProjectBasedRecord being submitted & one previously submitted?

Jump to solution
In a SUBMIT transition, Shell.Item will have a valid TS_ID and TS_ISSUEID. TS_UUID will be blank. In the newly created database record for the item, TS_ID will be 0 and TS_ISSUEID and TS_UUID will be blank.

To read the DB record I create an AppRecord and read the Record ID from Shell.Item.GetId, then use GetFieldValue("issueid") to read TS_ISSUEID, GetId to read TS_ID and GetUUID to read TS_UUID. By using my own AppRecord, I avoid the caching and value initialization done by SBM for Shell.Item.

Note that you can't use the GetFieldValue() function to read TS_ID or TS_UUID -- you have to used the dedicated functions GetId and GetUUID:

var arec_Db = Ext.AppRecord( Shell.Item.GetRecTableId ) ;

var n_Id = Shell.Item.GetId ;
var str_IssueId = "" ;
var str_UUID="" ;

arec_Db.Read(n_Id);

n_Id = arec_Db.GetId ;
str_IssueId = arec_Db.GetFieldValue("issueid") ;
str_UUID = arec_Db.GetUUID ;


return (n_Id==0 && str_IssueId.size==0 && str_UUID.size==0) ;

View solution in original post

curtiplas Frequent Contributor.
Frequent Contributor.

Re: Modscript: How do I detect the difference between new ProjectBasedRecord being submitted & one previously submitted?

Jump to solution
How
Paul Thompson wrote:

Assume a function like:
def Import_PDF_Data(pbr_Item , str_Fname) {

...
}
It may be passed a newly created Project Based Record item:
var pbr = Ext.CreateProjectBasedRecord( n_My_Primary_TableID ) ;

Import_PDF_Data(pbr , "... some path ...") ;
or it may be passed and item, possibly the current item, which was previously submitted.
Import_PDF_Data(Shell.Item , "... some path ...") ;


Is it possible for the function to quickly & easily detect the difference between the newly instantiated PBR and one that had been previously submitted?? I could check for previous transitions in the ChangeActions table, but that doesn't seem real speedy.

Fallback is to add a flag to the function's params that indicates "new item" / "one that's been around the block".


How/Why would an existing Project Based Record be submitted? Does the nature of the submit transition indicate that it would HAVE to be a new item?
0 Likes
PM Thompson Outstanding Contributor.
Outstanding Contributor.

Re: Modscript: How do I detect the difference between new ProjectBasedRecord being submitted & one previously submitted?

Jump to solution
In this case, the "Import_PDF_Data" function is being called in a transition ("Import data from PDF") on an existing "X" item, or in a transition ("Create new X and import data from PDF") from another workflow "ABC" to create a new "X" item.
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.