How to access Standard Change template change field values

Manju Shree
Tera Expert

Hi,

 

I have a requirement to get values present in standard change template. From a template I would like to get the value of owner group but unable to fetch them.

ManjuShree_0-1667231552911.png

Currently I'm using a script to get value present in array place 5 but the drawback is in few templates, the owner group value is placed else where, hence returning the wrong value. I would like to get the value of owner group field and the script I use is

 

var temp = new GlideRecord('std_change_record_producer');
temp.addEncodedQuery('active=true');
temp.addEncodedQuery('u_numberIN123');
temp.query();
while (temp.next()) {
var unqval = temp.getUniqueValue();
var rec = new GlideRecord('std_change_record_producer');
rec.get(unqval);
var util = new StdChangeUtilsSNC();
var opr = util._parseEncodedQuery(rec.template.template);
var assgrp = opr.vals[4]; //assgrp holds the 5th place value from the array.

 

Is there anyway that I could get the value of owner group irrespective of where it is placed.

Thanks for the response in advance.

 

Regards,

Manjushree

 

1 ACCEPTED SOLUTION

Manju Shree
Tera Expert

Thanks for the response. The below script helped me to get a particular value.

 

var temp = new GlideRecord('std_change_record_producer');
temp.addEncodedQuery('active=true');
temp.addEncodedQuery('u_numberIN123');
temp.query();
while (temp.next()) {
var unqval = temp.getUniqueValue();
var rec = new GlideRecord('std_change_record_producer');
rec.get(unqval);
var assgrp = rec.template.template;
gs.log(assgrp);
assgrp = assgrp.split("assignment_group=")[1];
var group = assgrp.substring(0,32);
gs.log(group);
}

View solution in original post

7 REPLIES 7

Sebas Di Loreto
Kilo Sage
Kilo Sage

This is a script I used in the past to figure out what Standard Change Templates have an inactive assignment group for example. You can run it in a background script.

I am sure it will help you to figure out your answer.

 

var templateList = "";

var splitListFields = "";

var separateFieldValues = "";

 

var grGlide = new GlideRecord('sys_template');

grGlide.addEncodedQuery('sys_class_name=std_change_template^table=change_request^active=true');

grGlide.orderByDesc('sys_created_on');

//grGlide.setLimit(1000);

grGlide.query();

 

while(grGlide._next()){

  templateList = grGlide.getValue("template");

  splitListFields = templateList.split("^");

 

  for(var i = 0; i < splitListFields.length; i++){

if(splitListFields[i].includes("=")){

separateFieldValues = splitListFields[i].split("=");

if(separateFieldValues[0]=='assignment_group'){

var grGroup = new GlideRecord('sys_user_group');

grGroup.addQuery('sys_id',separateFieldValues[1]);

grGroup.query();

if(grGroup.next()){

if(grGroup.active){

//gs.print('ACTIVE DL "' + grGroup.name + '" for template "' + grGlide.name +'"');

} else {

gs.print('INACTIVE DL "' + grGroup.name + '" for template "' + grGlide.name +'"');

}

}

}      

           }

  }

}

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.


Manju Shree
Tera Expert

Thanks for the response. The below script helped me to get a particular value.

 

var temp = new GlideRecord('std_change_record_producer');
temp.addEncodedQuery('active=true');
temp.addEncodedQuery('u_numberIN123');
temp.query();
while (temp.next()) {
var unqval = temp.getUniqueValue();
var rec = new GlideRecord('std_change_record_producer');
rec.get(unqval);
var assgrp = rec.template.template;
gs.log(assgrp);
assgrp = assgrp.split("assignment_group=")[1];
var group = assgrp.substring(0,32);
gs.log(group);
}

Just if you want to get anything u dont need use substring with counting numbers, try

var group = assgrp.split("^")[0];

 

It is a better way I guess if you want to get other values because they can be changed in template and have a different length then.