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.

adding dynamic text in Incident form

ofekg
Tera Contributor

In the incident form in the sow I want to add text under the priority field which describe the priorty value, will change as the priority changes.
i cant find a way to do it, needs help.

this is the text that should describe the priorities:
Critical - System or critical process is down
High - Partial loss of service with severe impact on the business and no workaround exists
Medium - Low business impact. The result is an inconvenience, which may require a temporary workaround

2 ACCEPTED SOLUTIONS

Ashish Parab
Mega Sage
Mega Sage

Hello @ofekg ,

 

Below is a onChange Client script that shows a field message when priority changes.

Script - 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (newValue == '1') {
        g_form.showFieldMsg('priority', 'System or critical process is down', 'info');
    } else if (newValue == '2') {
        g_form.showFieldMsg('priority', 'Partial loss of service with severe impact on the business and no workaround exists', 'info');
    } else if (newValue == '3') {
        g_form.showFieldMsg('priority', 'Low business impact. The result is an inconvenience, which may require a temporary workaround', 'info');
    }
}

 

Output-

ashish_parab_0-1733833179791.png

 

Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.

 

Thanks and Regards,

Ashish

 

View solution in original post

Hi @ofekg 

try this 

function onLoad() {
    var priority = g_form.getValue('priority');

    if (priority) {
      
        g_form.clearMessages();
    
        if (priority == '1') {
            g_form.showFieldMsg('priority', 'System or critical process is down', 'info');
        } else if (priority == '2') {
            g_form.showFieldMsg('priority', 'Partial loss of service with severe impact on the business and no workaround exists', 'info');
        } else if (priority == '3') {
            g_form.showFieldMsg('priority', 'Low business impact. The result is an inconvenience, which may require a temporary workaround', 'info');
        }
    }
}
Kindly mark it correct and helpful if it is applicable.

Thanks,

Raj

View solution in original post

12 REPLIES 12

raj chavan
Tera Guru
Tera Guru

hi @ofekg 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var priorityDescriptions = {
        "1": "Critical - System or critical process is down",
        "2": "High - Partial loss of service with severe impact on the business and no workaround exists",
        "3": "Medium - Low business impact. The result is an inconvenience, which may require a temporary workaround",
        "4": "Low - Minimal business impact, typically a cosmetic issue",
        "5": "Planning - Non-urgent, informational"
    };

    var description = priorityDescriptions[newValue]

    g_form.setFieldMessages('priority', description);
}

 

Kindly mark it correct and helpful if it is applicable.

Thanks,

Raj

ofekg
Tera Contributor

the setFieldMessege from you last line not working, why?
should u copy this to a client script? cause i tried it and i got: onChange script error: TypeError: g_form.showFieldMessages is not a function function () { [native code] }

when changing thr priority

Use g_form.showFieldMsg()

Kindly mark it correct and helpful if it is applicable.

Thanks,

Raj

@ofekg, Use showFieldMsg instead of setFieldMessages. Otherwise, Raj's answer will also help you.

 

Thanks,

Ashish