Clear the field value / Clear the variable value
The "issue"
When working with conditional visible fields / variables, these will mostly get visible thru (Catalog) Client Scripts or (Catalog) UI Policies. If you would fill a conditional visible field / variable, and then change the value of the field / variable will trigger (Catalog) Client Script or (Catalog) UI Policy which made the conditional field visible, the conditional visible field / variable might not be visible anymore. Though, what happens with the value you entered? If you do nothing... the value will just stay there. So actually if you would save the form the value will be stored, even if the field / variable is not visible.
This behavior doesn't have to be an issue, but in some cases could well be an issue! For example if other depending scripting is involved, what about reporting, list views, etc..
A picture says more than a thousand words... so an out-of-the-box example:- Platform UI- Story [rm_story]- Select an active Story- Check "Blocked"- Enter anything you'd like in the "Blocked reason" field- Uncheck "Blocked", "Blocked reason" becomes hidden again
- Save the Story
Notice that your "Blocked reason" is not saved, as the field isn't visible. This is actually due to Client Script "Clear Blocked Reason". If you would deactivate this Client Script, on save of the Story, the "Blocked reason" would remain even if the field isn't visible.
Pre-London
In the old days, you could add some limited scripting to empty the field / variable value. Thru both (Catalog) Client Script and (Catalog UI Policy). Notice the Client Script mentioned above, a great example of how this was done in the old days!
The scripting for this Client Script is only:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
if (newValue+"" == "false"){
g_form.setValue("blocked_reason", "");
}
}
For (Catalog) UI Policies something like below could do the job:
(Catalog) UI Policy, "Execute if false"
function onCondition() {
g_form.setValue('field_name', '');
}
London
With the introduction of London, the (Catalog) UI Policy Actions got enriched with a checkbox "Clear the field value" / "Clear the variable value". It does exactly as the label describes... if the (Catalog) UI Policy condition is true, and "Clear the variable value" / "Clear the field value" is selected, then it will be cleared.
Important note:
One thing to point out. You might have been used to set up (Catalog) UI Policies with conditions which would end up being true, and then adding (Catalog) UI Policy Actions which would, for example, make Visible is true, etc.. Though if you would select Clear the field value, this would conflict... So actually you have to rethink the logic. The condition should end up being false, Visible could then be false and Clear the field value can be selected.
The release notes describe this functionality pretty short. Anyway, a link to the release notes:
https://docs.servicenow.com/bundle/london-release-notes/page/release-notes/it-service-management/ser...
---
And that's it actually. Not much to it.
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group---
https://www.servicenow.com/community/developer-articles/clear-the-field-value-clear-the-variable-value/ta-p/2330119
