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.

Why this is not working?

user_20
Tera Contributor

Disable the Short Description field only if:
Caller’s department is “Finance”, AND • Priority is set to “1 – Critical”. 

 

    var priority = g_form.getValue('priority');
    g_form.getReference('caller_id', function(user) {
        if (user && user.department) {
            var deptName = user.department.name;

            alert("Department: " + deptName);    //returning undefined

            if (priority === '1' && deptName === 'Finance') {
               g_form.setDisabled('short_description', true);
            }
        }
    });
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@user_20 

you can't dot walk 2 level and hence won't get department name

compare department sysId

    var priority = g_form.getValue('priority');
    g_form.getReference('caller_id', function(user) {
        if (user && user.department) {
            var deptName = user.department;

            alert("Department: " + deptName); //returning undefined

            if (priority === '1' && deptName === 'financeDepartmentSysId') {
                g_form.setDisabled('short_description', true);
            }
        }
    });

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Ankur Bawiskar
Tera Patron
Tera Patron

@user_20 

if customer is not ok with hard-coded sysId then you can use client script + GlideAjax combination for your logic

GlideAjax Example Cheat Sheet (UPDATED) 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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