Native Form Client script not working in Portal

Community Alums
Not applicable

HI Team,

 

We have a custom application and form. We have written a onChange client script to populate the currency type based on other currency field. Its working fine in native UI on change as well as onsaving the record. While when we open the same record in service portal the same onChange client script also works.Its when we save the changes in Portal the currency type changes does not reflect. 

Below is the script:

  var amount_vat = parseFloat(g_form.getValue('amount_vat').replace(/[^0-9.-]+/g, ""));

    var ga = new GlideAjax('ClientSideUtils');
    ga.addParam('sysparm_name', 'calculateTax');
    ga.addParam('sysparm_taxcode', newValue);
    ga.addParam('sysparm_amountvat', amount_vat);
    ga.getXMLAnswer(result);

    function result(answer) {
        var curr = g_form.getValue('amount_vat');
        var currencytype = curr.split(";");
        var currency = currencytype[0];
        answer = JSON.parse(answer);
        g_form.setValue('amount_without_tax', currency + ";" + answer.amount_without_tax);
        g_form.setValue('tax_amount', currency + ";" + answer.tax_amount);


    }
 
The g_form.setValue statement in the last lines are updating the currency in the 2 fields. But when we save the form in service portal the changes does not reflect.
1 ACCEPTED SOLUTION

Hello @Community Alums ,

 

Yes, read-only fields will not be updated by Client Scripts in Service Portal. That is true for all field types, not just Currency fields. I think it is the intended behavior because it's known for many years, and it makes sense.

Here is a potential workaround.

 

Regards,

Robert

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

Hi Team,

 

I have noticed that the 2 fields which I am setting via g_form are readonly fields. When I make them editable then it works fine via service portal. Is there any issue?

Hi @Community Alums 

Check below link 

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0760420

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Hello @Community Alums ,

 

Yes, read-only fields will not be updated by Client Scripts in Service Portal. That is true for all field types, not just Currency fields. I think it is the intended behavior because it's known for many years, and it makes sense.

Here is a potential workaround.

 

Regards,

Robert