GlideRecord insert doesn't set Number field

garyopela
ServiceNow Employee
ServiceNow Employee

I have a transform map that will conditionally generate a record in another table via GlideRecord. It works great, except that it doesn't set the Number field.

Below is the javascript that is in the Field Mapping Script section of the transform map. It creates the contract just fine, but i need the Number to autmatically generate as well.

if (gr2.next()) {
contractSys = gr2.sys_id;
} else {
//here we need to create the new contract record
var de4 = new GlideRecord('ast_contract');
de4.initialize();
de4.vendor_contract = source.u_contract_id;
de4.insert();
contractSys = de4.sys_id;
gs.log("The Contract Sys is: " + contractSys);
}

Additionally, on the contract, the Number field has the following for the Default Value:
javascript:getNextObjNumberPadded();

However, it doesn't appear as if this is being run whenever the record in the contract table is being generated via a GlideRecord call.

I'm sure this is easy. I tried ge4.number = getNextObjNumberPadded(); but this didn't work (I didn't really think it would anyways because the GR call in the import script doesn't necessarily know what the next number should be).

Any Ideas?

Thanks!

Gary

5 REPLIES 5

Mark Stanger
Giga Sage

Try adding this directly before your 'insert()' in your script.

de4.number = getNextObjNumberPadded();


garyopela
ServiceNow Employee
ServiceNow Employee

Hey Mark, thanks for the suggestion. This is what I had already tried. I had a typo in my original post where I put ge4, but I had tried de4 originally as well. I tried it again just to be sure and it still doesn't work.

It actually seems to error out and never even creates the contract record if i have that line in the script.


Miguel Caldero3
Mega Expert

Does the number field gets generated automatically when you create a new record manually in the ast_contract table? If not, check in the Sys number table to see if there is a record for the ast_contract table.


Yes, the Number field does successfully generate a new number whenever I manually create an entry in the ast_contract table.