OnChange client script on dot walked field

sanvi
Tera Expert

Hi All,

 

I have a table called 'Allegation Outcomes' in which there is a dot walked field called Allegation type.

sanvi_1-1747203699596.png

An onchange client script needs to be configured on this field and on change of this field options have to be added and removed in the outcome field.

Issue: unable to configure the onchange 'Field name' for dot walked field.

 

Can anybody suggest an alternative or any other solution to achieve the results?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@sanvi 

it won't work that way for dot walked field.

Why are you allowing to change the Allegation type dot walked field on your current form?

If it has to be updated then it should be updated in the actual record and not on the form where it's shown as dot walked field

For your requirement you can use onLoad client script to check the value and then hide

function onLoad() {

    if (g_form.getValue('allegation.allegation_type') == 'your value') {
        g_form.removeOption('outcome', 'choice value');
    }

}

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

phgdet
Mega Sage

Hi @sanvi,

  1. Create an onChange Client script with any other field
  2. Open the Client script list view, filter on that client script
  3. Add column “Field name”
  4. Replace the Field name value with the dot walk field like: “table.field_name”

Note: dot walked field needs to be on the form

Original answer is provided by Mate Levai from this QA: https://www.servicenow.com/community/itsm-forum/onchange-client-script-for-changing-dot-walk-field/t...

Hi @phgdet ,

I tried the above steps. but once i update the field name from list view and once i update the script and save it the field name becomes empty.

 

hi @sanvi,

So that you need to update <field name> on the list once again after modify your code.
Or you can run a background script every time you modified your code.

var current = new GlideRecord("sys_script_client");
if (current.get("<your_client_script_id>")){
	current.setValue("field", "table.field_name"); //type your dot walked field here
	current.update();
}

Hi @phgdet ,

I feel this as risk. What if by miss the code stops working in PROD??

Is there any other way that this can be achieved?