Frequent Contributor.
Frequent Contributor.

How to access fields in Template table using JS in SM

Hi Folks,

I'm trying to access fields in Template table(say Interaction templates for example) using JS in SM.

can you please help me how to build query in script again Template table?

Requiremnet is, wanted to know is there any working Template(s) with a assignment group (say Application for example). Once i confirmed no such templates found, i can delete the assignment group.


Please let me know how can i achieve this.




1 Reply
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: How to access fields in Template table using JS in SM


maybe You can use my snippet as a starting point:

var _lng        = system.functions.lng;
var _nullsub    = system.functions.nullsub;

// we're looking for the assignment field in interactions (tablename: incidents)
var tablename   = 'incidents';
var assignfield = 'assignment';

// start
var query       = 'tablename="' + tablename + '"';
var file        = new SCFile('Template');
var rcode       = file.doSelect(query);

// iterate over the templates    
while (rcode == RC_SUCCESS) {
	var templatename        = file['name'];
	print('===> Template: ' + templatename);
	// all the values are in the structured array templateinfo
	var templateInfoLength  = _lng(file['templateInfo']) - 1;
    for (var idx = 0; idx < templateInfoLength; idx++) {
        var fieldname       = file['templateInfo'][idx][0];
        var fieldlabel      = file['templateInfo'][idx][3];
        var fieldvalue      = file['templateInfo'][idx][2];
        if (fieldname == assignfield) {
        	// check for assignment groups in the assignment field
        	if (_nullsub(fieldvalue, '').length !== 0) { 
        		print('found: ' + fieldvalue); // hint: the field it's an array, maybe there's more than one group        	
 	rcode       = file.getNext();

Good luck!


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.