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.




  • Hi,

    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!