- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 12:36 PM
Good day everyone! I have a bit of an issue that I just can't seem to figure out. I am writing a UI action to add multiple items to a transfer order by way of UI page slushbuckets. I have the code working for the most part but I get some errors when inserting record into the Transfer Order Line Table. From my troubleshooting it looks like i need to include the model from the asset as model is a required field on the transfer order line form.
UI Action on Transfer Line Item subform opens the UI Page that I wrote
UI Page has a PO order selector and based off of the PO selected the assets in stock and available populate for adding to the transfer order in the left slushbucket. When I add the assets to the right slushbucket and click ok is when the magic is SUPPOSED to happen.
The continueOK function calls a script include that adds assets to the transfer order line table. Here is my code from the addAsset function within my script include. TransferOrderID, containerID (client field requested) and values (assets) are passed in using sysparms (as you can see)
addAsset: function() {
var transferOrderID = this.getParameter('sysparm_transferOrderID');
var containerID = this.getParameter('sysparm_containerID');
var values = this.getParameter('sysparm_values').split(',');
for (x in values) {
var rec = new GlideRecord('alm_transfer_order_line');
rec.initialize();
rec.transfer_order = transferOrderID;
rec.u_container = containerID;
rec.asset = values[x];
rec.stage = 'draft';
rec.insert();
//Update Asset substatus to pending_transfer
var assetGR = new GlideRecord('alm_asset');
assetGR.addQuery('sys_id', values[x]);
assetGR.query();
if (assetGR.next()) {
assetGR.setValue('substatus', 'pending_transfer');
assetGR.update();
}
}
This code runs but I get an error on insert, most likely because I am not inserting model into the transfer order line table. That led me to the following code but it doesn't seem to be running at all now.
addAsset: function() {
var transferOrderID = this.getParameter('sysparm_transferOrderID');
var containerID = this.getParameter('sysparm_containerID');
var values = this.getParameter('sysparm_values').split(',');
var model = ''; //Store model sys_id for use in Transfer Order
var quantity = ''; //Store quantity on hand for asset for use in transfer order
for (x in values) {
//Query asset record to obtain model and quantity on hand
var assetGRNew = new GlideRecord('alm_asset');
assetGRNew.addquery('sys_id', values[x]);
assetGRNew.query();
if (assetGRNew.next()){
model = assetGRNew.getValue('model'); //should return sys_id of model
quantity = assetGRNew.getValue('quantity'); //should return quantity on hand of asset
}
var rec = new GlideRecord('alm_transfer_order_line');
rec.initialize();
rec.transfer_order = transferOrderID;
rec.u_container = containerID;
rec.asset = values[x];
rec.model = model; //use model var to update model field on TOL
rec.quantity = quantity; // use quantity var to update quantity field on TOL
rec.stage = 'draft';
rec.insert();
//Update Asset substatus to pending_transfer
//Query Asset table again - seems redundant
var assetGR = new GlideRecord('alm_asset');
assetGR.addQuery('sys_id', values[x]);
assetGR.query();
if (assetGR.next()) {
assetGR.setValue('substatus', 'pending_transfer');
assetGR.update();
}
//is this a better way to do this - comment out lines above for assetGR and uncomment these two lines.
//assetGRNew.setValue('substatus','pending_transfer');
//assetGRNew.setValue('active_to', true);
}
Any assistance will be greatly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 12:43 PM
I found a way to do this. First I called a separate function called getModel that performed a query on the model from the asset that was currently looping. Then I passed that and all of the sysparms into the new function to peform the addition of records to the transfer order line item table.
getModel: function() {
var transferOrderID = this.getParameter('sysparm_transferOrderID');
var containerID = this.getParameter('sysparm_containerID');
var values = this.getParameter('sysparm_values').split(',');
var orig_stockroom = this.getParameter('sysparm_fstockroom');
var dest_stockroom = this.getParameter('sysparm_tstockroom');
for (x in values) {
var assetGR = new GlideRecord('alm_asset');
assetGR.addQuery('sys_id', values[x]);
assetGR.query();
if (assetGR.next()) {
var model = '';
model = assetGR.model.sys_id;
if (model) {
this.addAsset2(values[x], model, transferOrderID, containerID, orig_stockroom, dest_stockroom);
} //else {
// this.addAsset2(values[x], '80f748331b803410efe2202ce54bcb46', transferOrderID, containerID, orig_stockroom, dest_stockroom);
//}
}//else {
//this.addAsset2(values[x], '19df8a0d0f9000109e7463cda8767e78', transferOrderID, containerID, orig_stockroom, dest_stockroom);
//}
}
},
addAsset2: function(assetID, model, transferOrder, container, origStockroom, destStockroom) {
var rec = new GlideRecord('alm_transfer_order_line');
rec.initialize();
rec.transfer_order = transferOrder;
rec.u_container = container;
rec.asset = assetID;
rec.model = model;
//rec.model = model;
rec.from_stockroom = origStockroom;
rec.to_stockroom = destStockroom;
rec.quantity_requested = '1';
rec.stage = 'draft';
rec.insert();
this.updateAsset(assetID);
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 12:43 PM
I found a way to do this. First I called a separate function called getModel that performed a query on the model from the asset that was currently looping. Then I passed that and all of the sysparms into the new function to peform the addition of records to the transfer order line item table.
getModel: function() {
var transferOrderID = this.getParameter('sysparm_transferOrderID');
var containerID = this.getParameter('sysparm_containerID');
var values = this.getParameter('sysparm_values').split(',');
var orig_stockroom = this.getParameter('sysparm_fstockroom');
var dest_stockroom = this.getParameter('sysparm_tstockroom');
for (x in values) {
var assetGR = new GlideRecord('alm_asset');
assetGR.addQuery('sys_id', values[x]);
assetGR.query();
if (assetGR.next()) {
var model = '';
model = assetGR.model.sys_id;
if (model) {
this.addAsset2(values[x], model, transferOrderID, containerID, orig_stockroom, dest_stockroom);
} //else {
// this.addAsset2(values[x], '80f748331b803410efe2202ce54bcb46', transferOrderID, containerID, orig_stockroom, dest_stockroom);
//}
}//else {
//this.addAsset2(values[x], '19df8a0d0f9000109e7463cda8767e78', transferOrderID, containerID, orig_stockroom, dest_stockroom);
//}
}
},
addAsset2: function(assetID, model, transferOrder, container, origStockroom, destStockroom) {
var rec = new GlideRecord('alm_transfer_order_line');
rec.initialize();
rec.transfer_order = transferOrder;
rec.u_container = container;
rec.asset = assetID;
rec.model = model;
//rec.model = model;
rec.from_stockroom = origStockroom;
rec.to_stockroom = destStockroom;
rec.quantity_requested = '1';
rec.stage = 'draft';
rec.insert();
this.updateAsset(assetID);
},