Shopping cart - Requested for

kmanning
Giga Contributor

When a user adds an item to the cart and changes the Requested for field, the Contact information (address) does not update.

Also, the Requested for defaults to the last person the user selected. As you can see Chris Overpeck is logged in and had previously changed the Requested for to Brenda Hoyt and the Contact information (address) did not update. I had him go back in and Brenda Hoyt is still selected as the Requested for. Ideally Requested for would default to the person who is logged in AND if it were changed the Contact information would update to reflect the address of the user that has been selected.

cart - req for.jpg

20 REPLIES 20

it is already there.. in delivery address



however you did show me what is missing on that table we have an onchange script set on the requested for that sets the address...



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


      var location = gel('requestor_location');


      if (!location)


              return;



      //if (isLoading && g_form.getValue('requestor_location') != "")


      //return;



      var gr = new GlideRecord('sys_user');


      gr.addQuery('sys_id', newValue);


      gr.query();


      if (gr.next()) {


              // Check if the Users Address is complete


             


              var text = '';


              var street = false;


              var cityStateZip = false;


              if (gr.street != null && gr.street != '') {


                      street = true;


                      text = gr.street + '\n';


              }


              if ((gr.city != null && gr.city != '') && (gr.state != null && gr.state != '') &&(gr.zip != null && gr.zip != '')) {


                      cityStateZip = true;


                      text += gr.city + ", " + gr.state + ", " + gr.zip;


              }


             


              // If the Users address is not complete


              // check if their location has a complete address


              // else use the Users partial address


              if(!street || !cityStateZip) {


                  var loc = checkLocation(gr.location);


                  if(loc != '')


                      text = loc;


              }



              g_form.setValue('requestor_location', text);


              location.focus();


      } else


              g_form.setValue('requestor_location', '');


}




function checkLocation( loc_id ) {


  var loc = new GlideRecord('cmn_location');


  loc.addQuery('sys_id', loc_id);


  loc.query();


  if(loc.next()) {


      var text = '';


      if ((loc.street != null && loc.street != '') && (loc.city != null && loc.city != '') &&


              (loc.state != null && loc.state != '') &&(loc.zip != null && loc.zip != '')) {


          return loc.street + '\n' + loc.city + ", " + loc.state + ", " + loc.zip;


      } else


          return '';


  } else


      return '';


}


one other script we have on that table is a set read only script on the requested for..   as an onload script.. i would make sure you do that either in a script or policy to ensure they don't change the requested for on the cart <users do stupid things>


Raymond,



Raymond Andrews


Can you share the script that makes the Requested for to Read only in the cart?



Thanks


Hello Suraj,



To make the requested_for field in cart screen read only you will have to modify the property



glide.sc.req_for.roles



add list of roles to whom the field should be readable.



find_real_file.png



glide.sc.req_for.roles


Inactive_Use603
Kilo Expert

Hi Kristina,



I usually don't use the OOB requested for field. Although all the suggestions are valid, I've always used the approach of having my own variables for 'requested for' and 'address' pre-populated when the catalog item is loaded using the current logged-in user. Using this approach you will allow the end user to select any user they want from the beginning. Once submitted a simple business rule can run to copy the "requested_for" variable value into the "Requested For" field from the sc_request table.



Considering a biggest approach and having in mind that you're actually using the cart as end user, I've created my own "requested_for" on the sc_req_item level. Consider the scenario where a user might select more than one time the same catalog item and add it into the cart but for different people each item; at the end you may consider the requester on the request level as the end user (current logged-in user) but different individuals on every requested item. This is a common scenario when a manager request items for its subordinates on their behalf.