Make a field mandatory if incident is created from new call

Community Alums
Not applicable

Hi All,

I want to make 'contact number' field on incident form to mandatory when incident is created from New Call. And mandatory only on new record and if assignment group is Software. Can someone help me in achieving this functionality.

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @Community Alums ,

try below onchange client script on assignment group

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (g_form.isNewRecord()) {
        if (newValue == 'b8ef24616fc331003b3c498f5d3ee434') { //add software group sysid
            g_form.setMandatory('contact_number', true); //give contact number backend name
        }
    }
}

Screenshot (612).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

10 REPLIES 10

Sonu Parab
Mega Sage
Mega Sage

@Community Alums 
1] Create onChange Client script for Assignment Group field. Try below script.

 

 if (g_form.isNewRecord()) {
        if (newValue == 'sysid_of_software') { 
            g_form.setMandatory('contact_number', true); 
        }
    }

 


If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thank You.

Pavankumar_1
Mega Patron

Hi @Community Alums ,

try below onchange client script on assignment group

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (g_form.isNewRecord()) {
        if (newValue == 'b8ef24616fc331003b3c498f5d3ee434') { //add software group sysid
            g_form.setMandatory('contact_number', true); //give contact number backend name
        }
    }
}

Screenshot (612).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Hello ,

 

Using sys id in scripts is not recommended . I understand you are thinking its client scripts and how to use gs.getProperty , but as per health scan reports this script will be marked as a finding.

Instead please use 

 var group = (g_form.getDisplayBox('assignment_group').value);

if (group == "Software"){
// same as above post .
}

 

Please mark it helpful when you get your Output correct.

Thanks

Community Alums
Not applicable

Hi @Pavankumar_1 

Above code does not fulfil my requirement. It is making field mandatory when incident is created from create new module. But my requirement is to make contact number mandatory if incident is created from new call.