Order Guide - 'Requested For' in the Checkout

sarahkapasi
Giga Expert

I've just created an Order Guide with a 'Requested For' Field in the initial tab.

I would like the "Requested for" field in the 'Checkout' tab to auto-fill with the 'Requested For' field from the initial tab.   Right now it puts the name of the person who opens the request, which I don't want.

Please advise on how to change that.

Thank you.

12 REPLIES 12

venkatiyer1
Giga Guru

Hi Sarah,





var CartAjaxClientUtils = Class.create();



CartAjaxClientUtils.prototype =   Object.extendsObject(AbstractAjaxProcessor, {


getRequestedForValue : function() {


var cart_item_id;


var cart_id =   this.getParameter("sysparm_cart_id")


var gr =   new GlideRecord("sc_cart_item");


gr.addQuery("cart.sys_id", cart_id )


gr.query();



while(gr.next() ) {


cart_item_id = gr.item;


}


var itemGR =   new GlideRecord("sc_item_option");


itemGR.addQuery("Question", "Requested For");


itemGR.addQuery("cart_item", cart_item_id);


itemGR.query();


while(itemGR.next()) {


return itemGR.value;


}


},


type: "CartAjaxClientUtils"


});





Then an onload client script for sc_cart table which calls the above utils and submits the value


for getting the sysparm_cart_id you can use gel('sysparm_item_guid').value and for setting the requested for you can use $('sc_cart.requested_for').value


Thank you!  



I'm sorry I am new to this, so I was wondering what I should select as the table and should the type be onload?


venkatiyer1
Giga Guru

Hi Sarah,



No issues. You can select sc_cart as table and type would be onload.


Ok this is what I did and it still doesn't work.   I'm sorry but I didn't understand the 2nd part to your answer :



for getting the sysparm_cart_id you can use gel('sysparm_item_guid').value and for setting the requested for you can use $('sc_cart.requested_for').value



find_real_file.png


venkatiyer1
Giga Guru

Hi Sarah,



No the above script you have pasted is not an onload client script. It is a script include.



Create a script include named CartAjaxClientUtils with client callable check box checked.




  1. var CartAjaxClientUtils = Class.create();  
  2.  
  3. CartAjaxClientUtils.prototype =   Object.extendsObject(AbstractAjaxProcessor, {  
  4. getRequestedForValue : function() {  
  5. var cart_item_id;  
  6. var cart_id =   this.getParameter("sysparm_cart_id")  
  7. var gr =   new GlideRecord("sc_cart_item");  
  8. gr.addQuery("cart.sys_id", cart_id )  
  9. gr.query();  
  10.  
  11. while(gr.next() ) {  
  12. cart_item_id = gr.item;  
  13. }  
  14. var itemGR =   new GlideRecord("sc_item_option");  
  15. itemGR.addQuery("Question", "Requested For");  
  16. itemGR.addQuery("cart_item", cart_item_id);  
  17. itemGR.query();  
  18. while(itemGR.next()) {  
  19. return itemGR.value;  
  20. }  
  21. },  
  22. type: "CartAjaxClientUtils"  
  23. });




Then seperately create a client script with type onload and on table sc_cart say with name setRequestedForFromCatalogItem




function onLoad() {


    var cart_id = $('sysparm_item_guid').value;
   
var cartAjaxUtil = new GlideAjax('CartAjaxClientUtils');
    cartAjaxUtil.addParam(
'sysparm_name', 'getRequestedForValue');
    cartAjaxUtil.addParam(
'sysparm_cart_id', cart_id);
    cartAjaxUtil.getXML(fillRequestedFor);


  function fillRequestedFor(response) {


      var answer = response.responseXML.documentElement.getAttribute("answer");


      $('sc_cart.requested_for').value = answer;


   


  }


}


Hope that helps.