Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Map the price in the price type field

SK41
Giga Guru

Hi,

 

I have a requirement where I have two string fields on a form, one is "currency code" and other is "value". The user enters currency code in  the "currency code" field and price in the "value" field. What I have to do is as soon as user enters data in these two fields, I have to auto populate another field which is of "price" type with both these values.

 

For example, If user enters,  "$" in currency code field and " 42" in value field then the price type field should be auto populated as shown in below screenshot: 

aa.png

The choice in the price should get auto populated with the "$" and value should be captured also in price field.

How can I achieve this requirement? Can you pls assist.

 

Thanks!

3 REPLIES 3

nitinsharma2510
Giga Guru

Hi @SK41 ,

 

This can be achieved using Client Scripts. It would require 3 client scripts:

  • onLoad Client Script to set the value for existing records.
  • onChange Client Script for Currency string field to update price when currency is updated.
  • onChange Client Script for Price string field to update price when currency is updated.

The following code should work where more currency symbols can be added as per your requirement:

var currency = "";
var priceFinal = "";
switch(g_form.getValue('u_currency')){
	case '$':
		currency = "USD";
		break;
	case "£":
		currency = "GBP";
		break;
}
priceFinal = currency + ";" + g_form.getValue('u_price_string');
g_form.setValue('price', priceFinal);

 

Thanks,

Nitin Sharma

Hi,

 

This is not setting the currency choice and price value in the price type field.

Hi,

 

Ideally the price type field should be set as follows:

                                      Currency_code;Value

For example, I tried "USD;19.00" or "GBP;25.01" and it worked. Kindly check the backend values of the currency symbols. OOB values are set as $ = USD, £ = GBP etc.