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.

Auto populate the Assigned vendor field based on assignment group on work order task( wm_task)

Community Alums
Not applicable

I want to auto-populate the assigned vendor (assigned_vendor) when the assignment group changes on work order task ( wm_task) but onchange script is not working.

 

script:

field: assignment group

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '')
        return;

    var assignedvendor = g_form.getValue("assigned_vendor");

    if (assignedvendor == "") {
        var assignmentgrp = g_form.getReference("assignment_group");
        if (assignmentgrp != null)
            g_form.setValue('assigned_vendor', assignmentgrp.vendors.toString());
 
            g_form.setMandatory('assigned_vendor',true);
    }
}
 
Assigned vendor: 
reference qualifier: javascript:'sys_idIN' + current.assignment_group.vendors
issue: it's not immediately clearing the value of assigned vendor on work order task(wm_task).
any help on this really appreciated!
 
1 REPLY 1

Zach Koch
Giga Sage

Are you saying it is working, but not when the form loads? If so remove the isLoading from the if block

  if (isLoading || newValue == '')
        return;
If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!