How to Override Default for Requested For Field

ajlabate
Kilo Expert

The Requested for field is always set to whoever is creating the request (the person presently logged in).   I'm trying to make it something different and all my attempts have failed.   Ultimately, I'd like it to be the name of the person that is entered into the Variable (Requested for).   I checked the dictionary for the field and saw that it had a default value as javascript:gs.getUserID()     I removed this default value but the field gets set anyway.   I tried to set it in the beginning of the workflow with a Run Script activity to the variable entry submitted by the user but that does nothing.   No matter what I do, the field is always set to the person entering the request.   I need that person to be able to designate someone else as the requested for person.   Any ideas?

 

This is the script in the workflow:

var reqRecord = current.request.getRefRecord();

reqRecord.requested_for = current.variable_pool.requested_for;

1 ACCEPTED SOLUTION

yes sir.. just replace the entire script with the below and it should work like magic.



___________________




function onChange(control, oldValue, newValue, isLoading) {


   


    if (newValue){


          var gr = new GlideRecord('sc_cart');


          gr.addQuery('user', g_user.userID);


          gr.query();


          gr.next();


          gr.requested_for = newValue;


          gr.update();


    }


}


View solution in original post

55 REPLIES 55

The variable I use never changes.   It is always called requested_for.   I copied your script into a client script that I named "Set_Req_For".   The Type is onChange, Table is sc_request, Field name is Requested for.   Where do I call out this new script?   Is it in the beginning of the workflow?   And how do I reference it?


this is on a catalog item correct?! so it goes on the catalog item itself in the catalog client scripts area sorry if i wasn't clear on that.


Yes it is.   Do I overlay what is already in the Script area?


yes sir.. just replace the entire script with the below and it should work like magic.



___________________




function onChange(control, oldValue, newValue, isLoading) {


   


    if (newValue){


          var gr = new GlideRecord('sc_cart');


          gr.addQuery('user', g_user.userID);


          gr.query();


          gr.next();


          gr.requested_for = newValue;


          gr.update();


    }


}


I tested it, but the Requested for field is blank.   I didn't change the script at all.   Should I try replace newValue to something else here?:


gr.requested_for = newValue;