Set parent field mandatory when New button clicked on related list

Aruna Sree Yela
Tera Guru

Hi,

 

When user clicks New button on incident tasks related list from incident form, then it should abort the user to fill a mandatory field on incident form

 

Simply, set field mandatory on incident when user clicks on new button in related list.

 

I tried the below reference(both ui action and script), I can see the message I set but its not setting the field mandatory

https://www.servicenow.com/community/developer-forum/make-parent-field-required-when-child-task-is-c...

 

Can anyone please help on this issue.

 

Thanks:)

 

4 REPLIES 4

Dnyaneshwaree
Mega Sage

Hello @Aruna Sree Yela,

Please try to get value of variable that required to be mandatory using logs and also post images and script here.

Please accept my solution if it works for you and thumps up to mark it as helpful.

Thank you!!

Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru

@Dnyaneshwaree ,

 

Here is the script

 

ArunaSreeYela_3-1718632037865.png

 

 

ArunaSreeYela_1-1718631882340.png

 

function onCondition() {
    if (g_form.isNewRecord()) {

        var parentRec = g_form.getReference('incident', getParent);
    }
}

function getParent(parentRec) {
	
    g_form.addInfoMessage('test message');
    g_form.addInfoMessage(parentRec.u_product_model);
    g_form.setMandatory('parentRec.u_product_model', true);
}

 

 

Output:

 

ArunaSreeYela_2-1718631963923.png

 

Thanks

 

Dnyaneshwaree
Mega Sage

Hello @Aruna Sree Yela ,

function onCondition() {
    if (g_form.isNewRecord()) {

        var parentRec = g_form.getReference('incident', getParent);
    }
}

function getParent(parentRec) {
	
    g_form.addInfoMessage('test message');
    var product = g_form.getValue('parentRec.u_product_model') ;
    var prodModel= setDisplayValue(product);  // you can use quote for product and if there is no any need for 
    setDisplayValue then you can remove this line and add product instead prodModel in setMandatory line.
    g_form.addInfoMessage(parentRec.u_product_model);
    g_form.setMandatory('prodModel', true);
    alert('Please fill mandatory fields');
    return false;  //Abort submission
   }
return true;
 Let me know if you are facing any issue in this script. 

Please accept my solution if it works for you and thumps up to mark it as helpful.

Thank you!!

Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru

Hi @Dnyaneshwaree 

 

Thanks for your time!

No luck, I can see the infomessages and alert on task form but the field on incident is not becoming mandatory.

 

Thanks