Populate the watch list field from a variable that is on every catalog item

rachelconstanti
Mega Sage

I have a variable set with a field of "requested_for" on every catalog item.  I need that field to be copied to the watch list so that the requested for can receive email notifications.

I've seen some articles on this subject but none really seem to answer the question.

I know that I can do this through a business rule - I need help with what I need to do for a script.  Any help is appreciated.

~Rachel

 

1 ACCEPTED SOLUTION

Probably the easiest way would be to create an onBefore Business rule on the Requested Item table that will take the value from the Requested for [requested_for] variable and insert into the Watch list [watch_list] listing. Since the Watch list field is an array of sys_id values, you will need to push the value from your variable (which I am guessing is a reference field) into the Watch list field. Here are the details for the Business Rule:

Name: Set Watch list from Requested for
Table: Requested Item [sc_req_item]
Advanced: true
Description: Copies the Requested for variable into the Watch list field
When: before
Order: 100
Insert: true
Update: false
Delete: false
Query: false
Script:

(function executeRule(current, previous /*null when async*/) {
    var reqFor = current.variables.requested_for;
    var wlArray = [];
    if (reqFor != '') {
        wlArray.push(reqFor.toString());
        current.watch_list = wlArray.toString();
    }
})(current, previous);

Let us know if this works for you.

View solution in original post

8 REPLIES 8

Jaspal Singh
Mega Patron
Mega Patron

Hi Rachel,

 

Try using something as below (untested) in after insert business rule:

var itemVariables = '';
var Rvar = new GlideRecord('sc_item_option_mtom');
Rvar.addQuery('request_item', current.sys_id);
Rvar.addQuery('sc_item_option.item_option_new','Requested for'); //considering Request for is Question label
Rvar.query(); 
while(Rvar.next()) {
var fieldname = Rvar.sc_item_option.item_option_new.getDisplayValue();
gs.log('Requested for is ',fieldname);
}
current.watch_list= fieldname; 
current.update();

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

When I submit a request through the portal (ESS) i get this error

find_real_file.png

I am guessing that you want to populate the Watch list [watch_list] field on the Requested Item [sc_req_item] record.

Probably the easiest way would be to create an onBefore Business rule on the Requested Item table that will take the value from the Requested for [requested_for] variable and insert into the Watch list [watch_list] listing. Since the Watch list field is an array of sys_id values, you will need to push the value from your variable (which I am guessing is a reference field) into the Watch list field. Here are the details for the Business Rule:

Name: Set Watch list from Requested for
Table: Requested Item [sc_req_item]
Advanced: true
Description: Copies the Requested for variable into the Watch list field
When: before
Order: 100
Insert: true
Update: false
Delete: false
Query: false
Script:

(function executeRule(current, previous /*null when async*/) {
    var reqFor = current.variables.requested_for;
    var wlArray = [];
    if (reqFor != '') {
        wlArray.push(reqFor.toString());
        current.watch_list = wlArray.toString();
    }
})(current, previous);

Let us know if this is what you are looking for.

ccajohnson
Kilo Sage

I have a few clarifying questions that will assist in narrowing our solution:

  1. Is the requested_for variable a reference type variable?
  2. Which table is that variable to be copied to? (Request, Requested Item, Catalog Task)?

Once this is clarified, we should be able to solution accordingly.