How to change Price in the Catalog Item form?

Danny Sun
Tera Guru

Hello,

        I need to add a text field called Order Quantity in the catalog item form, this form just numeric only, if this field changes, I need to update the "Price" to multiply the entire cost of the catalog item by the number in the "Order Quantity" field, and the new price will be update date to the "Shopping Cart" when the catalog item be checked out.

        I don't know how to get the "Price" in the catalog item using the Client Script? How to update the "Price" when the "Order Quantity" field changes? And how to update the "Price" to the "Shopping Cart" when the when the catalog item be checked out?

        Do you have any suggestions?

        See the picture below:

New Bitmap Image.bmp

Best Regards,

Danny

1 ACCEPTED SOLUTION

Hi Jessica,



Not sure you would want to do this using the below approach, i have replaced the 'dropdown box' with a 'text box' like below



find_real_file.png



changes done:



macro name: sc_order_item_price_quantiy   ( this is under maintain cart layouts--> Target type: Browser Widget (3)--> Item Ordering Widget)



Original lines:



  <span id="quantity_span">


                                      <g:evaluate expression="var choice_list = GlideScriptChoiceList.getChoiceList('sc_cart_item', 'quantity');" />


                                      <select id="quantity" onchange="orderItemWidget.calcPrice()">


                                              <g:options choiceList="${choice_list}" choiceValue="${jvar_cart_item.quantity}" />


                                      </select>


    </span>




replaced lines:



  <span id="quantity_span">


                                      <g:evaluate expression="var choice_list = GlideScriptChoiceList.getChoiceList('sc_cart_item', 'quantity');" />



  <div class="select-editable">



  <input type="text" id="quantity" name="quantity" onchange="orderItemWidget.calcPrice();"/>



  </div>


  </span>



<style>


  .select-editable {


        position:relative;


        background-color:white;


        border:solid grey 1px;


        width:120px;


        height:18px;


}


.select-editable select {


        position:absolute;


        top:0px;


        left:0px;


        font-size:14px;


        border:none;


        width:120px;


        margin:0;


}


.select-editable input {


        position:absolute;


        top:0px;


        left:0px;


        width:100px;


        padding:1px;


        font-size:12px;


        border:none;


}


.select-editable select:focus, .select-editable input:focus {


        outline:none;


}


</style>





Note: This macro is read only as this is OOTB one, you will have to create   a new one over here:( maintain cart layouts--> Target type: Browser Widget (3)--> Item Ordering Widget)) and delete the original macro from here (not the macro record))



Disclaimer: Any changes made to the OOTB macros or any other objects will not be upgraded during version upgrades, its our sole responsibility to do so.





In case you dont wanna follow the above approach!   you may refer this link: Re: Overwriting CatalogPriceCalculator script include




Please make answer as appropriate or correct!, if it helped!



Regards


Yogish


View solution in original post

19 REPLIES 19

bryansmith
Kilo Explorer

I wanted to do something similar, but a calculation to work out cost of storage based on Tier of storage and GB. The simplest way I found to do this was to have onchange scripts for the 2 items then a read only field for the cost.



This is then submitted and the workflow kicks in. First step in the workflow is to set the price on both the request item and the request. do



current.price = current.variables.cost;


var sc_request = new GlideRecord('sc_request');


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


sc_request.query();


if (sc_request.next()){


  sc_request.price += current.variables.cost;


  sc_request.update();


}




There seems to be a Known Error of requests not updating when request item changes so you could i guess use this instead of the script. you still have to set current.price to the field you created in the workflow.




ServiceNow KB: PRB600689: Price in a Catalog Request is not updated if Requested Items change. (KB05...


You could also accomplish this with a table that maps tier, storage, and price (latter must be named price or u_price, and must be a Currency field).  Then your price variable would be a reference to that table, and would need to include the (hidden) flag 'Pricing influence' (or something similar; going from memory).  That makes your workflow a bit cleaner and less error-prone (if you need to change it).

yogesh15dd
Tera Guru

Hi Danny, have the similar situation, may i know what approach did you follow to achieve this?, did you use 'Order Quantity' field only?



Regards


Yogish


jleyco
Mega Contributor

Hi Danny - were you able to find a solution for this? I'm working on a similar update.


Hi Jessica,



Not sure you would want to do this using the below approach, i have replaced the 'dropdown box' with a 'text box' like below



find_real_file.png



changes done:



macro name: sc_order_item_price_quantiy   ( this is under maintain cart layouts--> Target type: Browser Widget (3)--> Item Ordering Widget)



Original lines:



  <span id="quantity_span">


                                      <g:evaluate expression="var choice_list = GlideScriptChoiceList.getChoiceList('sc_cart_item', 'quantity');" />


                                      <select id="quantity" onchange="orderItemWidget.calcPrice()">


                                              <g:options choiceList="${choice_list}" choiceValue="${jvar_cart_item.quantity}" />


                                      </select>


    </span>




replaced lines:



  <span id="quantity_span">


                                      <g:evaluate expression="var choice_list = GlideScriptChoiceList.getChoiceList('sc_cart_item', 'quantity');" />



  <div class="select-editable">



  <input type="text" id="quantity" name="quantity" onchange="orderItemWidget.calcPrice();"/>



  </div>


  </span>



<style>


  .select-editable {


        position:relative;


        background-color:white;


        border:solid grey 1px;


        width:120px;


        height:18px;


}


.select-editable select {


        position:absolute;


        top:0px;


        left:0px;


        font-size:14px;


        border:none;


        width:120px;


        margin:0;


}


.select-editable input {


        position:absolute;


        top:0px;


        left:0px;


        width:100px;


        padding:1px;


        font-size:12px;


        border:none;


}


.select-editable select:focus, .select-editable input:focus {


        outline:none;


}


</style>





Note: This macro is read only as this is OOTB one, you will have to create   a new one over here:( maintain cart layouts--> Target type: Browser Widget (3)--> Item Ordering Widget)) and delete the original macro from here (not the macro record))



Disclaimer: Any changes made to the OOTB macros or any other objects will not be upgraded during version upgrades, its our sole responsibility to do so.





In case you dont wanna follow the above approach!   you may refer this link: Re: Overwriting CatalogPriceCalculator script include




Please make answer as appropriate or correct!, if it helped!



Regards


Yogish