The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Condition on client script to check if the record is new

Sofija
Giga Expert

Hi All,

I need to auto-populate a specific assignment group on Incident table when a new record is being raised and when environment of non-prod is selected. I did the second part - populating the assignment group when env=non-prod and clearing it otherwise. However, I am not sure how to add condition that this should happen only for new records, i.e. if the record already exists/has been raise, we should be able to re-assign the ticket to any other team.

My current onChange (field: environment) client script:

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

var env = g_form.getValue('u_environment');

if (env == 'Non-production') {
  g_form.setValue("assignment_group", "a4f63ac36ffb2100dbb7db141c3ee4a6");
}
else
  {
  g_form.setValue("assignment_group", "");
 
}
}

Does anyone have ideas of how I could add the condition? I think I need to be using isNewRecord(), but not sure how exactly to plug it in.

Any suggestions are appreciated!

Thank you,

Kamile

1 ACCEPTED SOLUTION

jcfourie
Kilo Expert

Hi Kamile



For the new record? Do you simply want to check if this form is going to create a new record in the incident table? In that case you can just use



if(g_form.isnNewRecord()){


        do whatever you need it to do


}else{


        do something else


}


or in your specific case you could add it to the original if statement



if (g_form.isNewRecord() && env == 'Non-production') {



But if you are wanting to check if the same type of record has already been created, then it's a much more complicated process.


View solution in original post

5 REPLIES 5

jcfourie
Kilo Expert

Hi Kamile



For the new record? Do you simply want to check if this form is going to create a new record in the incident table? In that case you can just use



if(g_form.isnNewRecord()){


        do whatever you need it to do


}else{


        do something else


}


or in your specific case you could add it to the original if statement



if (g_form.isNewRecord() && env == 'Non-production') {



But if you are wanting to check if the same type of record has already been created, then it's a much more complicated process.


Thank you! I knew it was something simple but I forgot about g_form


marcguy
ServiceNow Employee
ServiceNow Employee

g_form.isNewRecord()


HV1
Mega Guru

Here's the example on how to use isNewRecord():   http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#isNewRecord&gsc.tab=0



- Hardik Vora