The requested for shows incorrect on Request

pennieturner
Mega Guru

I have a bit of an issue at the moment with the requested for field.

We use two fields on the request:

Requested By - Default is the current USERID

Requested For - default is blank

On the actual request the requested by is the user raising the request and the requested for is the person who the request is for IE

Requested By - Pennie

Requested For - Tracy

After I have gone through the 2 stage shopping cart, the request shows as both as Pennie, and the actual requested Items show correctly as pennie for the requested by and tracy for the requested for.


We are on Calgary release and I'm stuggling to find why its not setting it correctly on the request?


Can anyone help?

We have the requested for delivery details turned off because of this error (UI Macro called catalog_requested_for), as on the cart it shows wrong aswell, but if you go back to the request (eg edit it) it shows what you actually put.

Thank you in advance

1 ACCEPTED SOLUTION

poyntzj
Kilo Sage

We have this as a BR in sc_request


set as a Before Insert / Update



var grRITM = new GlideRecord('sc_req_item');  


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


grRITM.query();  


while (grRITM.next()) {  


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


      current.requested_for = grRITM.variables.requestor_name;


  }  


}



Added by someone from Servicenow for us



We also have a Variable Set called requested_for_vars


that has the requested_for variable in there



Otherwise I would suggest you look at the audit history and see if it is changing as well as looking at all your BR's to see if they are doing anything


View solution in original post

11 REPLIES 11

poyntzj
Kilo Sage

We have this as a BR in sc_request


set as a Before Insert / Update



var grRITM = new GlideRecord('sc_req_item');  


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


grRITM.query();  


while (grRITM.next()) {  


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


      current.requested_for = grRITM.variables.requestor_name;


  }  


}



Added by someone from Servicenow for us



We also have a Variable Set called requested_for_vars


that has the requested_for variable in there



Otherwise I would suggest you look at the audit history and see if it is changing as well as looking at all your BR's to see if they are doing anything


Thats fantastic thank you, it worked a treat




Julian I wonder if you could help me further on this one.



I am trying to do this for the requested_by instead of the requested for.   At present the default for the requested_by is the current userID, if the person changes the requested_by on the form, it does not go through and it reverts back to the default (userID of the current person).



I used your script to set the requested_by, but it did not work.



I am guessing because we have 3 variables called requested_by, although we have 3 variables called requested_for and it still worked ok on that.



I tried renaming the variable to someone else IE userrequested_by, but, still it does not work



var grRITM = new GlideRecord('sc_req_item');



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


grRITM.query();


while (grRITM.next()) {


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


  current.userrequested_by = grRITM.variables.userrequested_by;


  gs.addInfoMessage("current userrequested by = " +current.userrequested_by); //This shows as the correct user


  }


}



Do you have any ideas on how I can get this working?



I can't see anything in the audit history and I can't see an other BR's updating the requested_by field



Thank you in advance


We do not have a Requested By field here.   Do you have this declared as a variable called requested_by, and is that field in your REQ / RITM records ?



So I use the Service Catalog and Request something


I choose "Requsted For" and I choose Pennie


I choose "Requested By" and I choose Jane



Now, when I look in the system


the REQ record is showing


Requested For = Pennie ?


Requested By   = Julian or Jane ?



On the RITM record(s)


Requested For = Pennie ?


Requested By   = Julian or Jane ?