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

Here's a screen shot of what I did:


SN Script.jpg


ok you can uncheck applies on requested item and catalog task.. it is only needed in the catalog item view...




for one of the previous you had created a before BR.. was that disabled already??


...   it should work it is working on all the items we have an has worked for others.


Hi Doug, I wonder if you can help me with a related problem?



I too am having the same problems with request, my trouble is the requested by.



On the actual request (before its submitted) the requested_by field is defaulting to the current.userID.   We manually change this, but when the request and requested item are set up the values are changed to the userID again.



I have added your CS script and the BR, and now the requested item gets the correct requested by, but, the request remains the UserID of the current session.



Can you help?   Im struggling to get this working ;(



CS is as follows - onChange requested_by



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_by = newValue;


          gr.update();


  }


}



BR is as follows: onBefore insert and update



var grRITM = new GlideRecord('sc_req_item');



grRITM.addQuery('request', current.sys_id);


grRITM.query();


while (grRITM.next()) {


  if (!JSUtil.nil(grRITM.variables.requested_by)) {


  current.requested_by = grRITM.variables.requested_by;


  }


}



Thank you in advance




Pennie did you put the client script on the catalog item.. or on the table.. it should go on the item.. that way on the checkout screen it is correct...



the big clue here is the checkout cart... is the requested for correct there.. if not we are looking at a problem with the item.. if so we are looking at a table issue.


Yes its on the catalog item.



I've enabled the UI Macro to show the requested for on the two stage check out, but it shows the userID of the current session, not the person I put on the requested for.   But, this works right, as we can have multiple requested items on one request, so on the request I want the requested for to be the same as the requested by, and the requested item shows correct for the requested for (the person actually entered on the calatog item) its the requested by thats not working correct.   It keeps picking up the userID of the current logged in session.



I put some debugging on the business rule, and the sys_ID for the current.requested_by at the end when it sets it was right, so something is happening after the CS and BRs have run, but I can't find where