GlideRecord insert doesn't set Number field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2012 09:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2012 07:12 AM
Okay, I was able to solve this. After Mark had pointed me to the getNextObjNumberPadded, and I had already though of that, I just had to find that function and see what it was doing. I was suspsecting that it didn't know for which table to generate the next number since I was using a transform map, it was probably looking for the import set table or something. So, I found the global BR that has that function in it and copied some of it and tailored it to my transform map. Below is what I came up with, and it works like a charm:
var de4 = new GlideRecord('ast_contract');
de4.initialize();
de4.vendor_contract = source.u_contract_id;
var nm = new NumberManager("ast_service");
de4.number = nm.getNextObjNumberPadded();
de4.insert();