Write script include with advanced reference qualifier to return multiple values

sujithra1
Kilo Explorer

I have a form, by using one field from the form (name), I have to fetch the request number, requested item, and state is approved, from the task table (request raised by the same user) to populate values to other form values(request number, requested item, and state is approved)by using script include using reference qualifier.

I am a beginner in service now, please help me with the code.

 

My code:

 

Script includes:

var Approved_MPS = Class.create();
Approved_MPS.prototype = Object.extendsObject(global.AbstractAjaxProcessor,{
getStoreIDs: function(a){

gs.log("Script Include called ");
var a= a;
gp = [];
if(!a)
return;
if(a){
var gr = new GlideRecord('task');
gr.addQuery('requested_for',a);
gr.query();
while(gr.next()) {
gp.push(gr.sys_id.toString());
}
gs.info('Im here');
return 'sys_idIN' + gp;

}
},
type: 'Approved_MPS'
};

});

1 REPLY 1

Adrian Ubeda
Mega Sage
Mega Sage

Hi sujithra, 

I'm not sure if this will achieve your need. With this you'll get all the task related to the query you are applying on task table but only in one reference field (this field, also must be referenced to task), multiple fields won't be filled with this automatically.

However, I've checked you code, try this as below:

var Approved_MPS = Class.create();
Approved_MPS.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    getStoreIDs: function(a) {

        gs.log("Script Include called ");
        gp = [];
        if (a == '') {
          return;
        }else{
          var grTask = new GlideRecord('task');
          grTask.addQuery('requested_for', a);
          gr.query();
          while (gr.next()) {
              gp.push(gr.sys_id.toString());
          }
          gs.log('Im here');
          return 'sys_idIN' + gp.join();
        }
    },
    type: 'Approved_MPS'
});

If it was helpful, please give positive feedback.
Thanks,

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆