Default Source and Destination Stockroom on the Source Request UI Page SOLVED

Community Alums
Not applicable

I have found a solution for setting the default source stockroom and default destination stockroom on the Source Request ($source_request) UI page. The solution is adding functionality to the ProcSourceRequestManager script include, and the key was discovering the name of a property that is not disclosed to us, item.sourceDefault.transfer, which I inferred from the name of the local order property, item.sourceDefault.local.

 
Step 1: Create a function to populate your transfer order information.
 
* Set the sourceStockroomID and sourceStockroomName variables to the stockroom that you want to be the default source stockroom.
* Please note: I am setting the default destination stockroom to a variable within the requested item. You will have to modify that to suit your specific needs. Please reach out if you need assistance with that portion.
 
 
_populateTransferOrderInfo: function(item) {
       
        var sourceStockroomID = 'SYS ID of YOUR STOCKROOM';
        var sourceStockroomName = 'DISPLAY NAME of YOUR STOCKROOM';
        var count = 0;
        var gr = new GlideAggregate('alm_asset');
        global.AssetUtils.addAssetQuery(gr, global.AssetUtils.ASSET_FUNCTION_FEATURE.SOURCING);
        gr.addQuery('model', item.cat_item.model);
        gr.addQuery('install_status', global.AssetUtils.INSTOCK_STATUS);
        gr.addQuery('substatus', global.AssetUtils.AVAILABLE_SUBSTATUS);
        gr.addQuery('stockroom', sourceStockroomID);
        gr.addAggregate('SUM', 'quantity');
        gr.groupBy('model');
        gr.query();
        if (gr.next()) {
            count = gr.getAggregate('SUM', 'quantity');
        }
        var stckroom = {};
        stckroom['name'] = sourceStockroomName;
        stckroom['sys_id'] = sourceStockroomID;
        stckroom['instock'] = count;
        item.sourceDefault.transfer = JSON.stringify(stckroom);
        //End of custom default source stockroom

        //Set the destination stockroom based on the deliver to site variable
        var ritmGR = new GlideRecord('sc_req_item');
        ritmGR.get(item.sys_id);
        var deliverToSite = ritmGR.variables.deliver_to_site.sys_id;
        var stockGR = new GlideRecord('alm_stockroom');
        stockGR.get(deliverToSite);
        var destStockroom = {};
        destStockroom['value'] = stockGR.getValue('sys_id');
        destStockroom['displayValue'] = stockGR.getValue('name');
        item.destDefault.transfer = JSON.stringify(destStockroom);
        item.destDefault.purchase = JSON.stringify(destStockroom);

        return item;
    },

 

Step 2: Call your new function from the _getRequestData function in the script include.
 
austin_curry_1-1710954978516.png

 

That's all there is to it!

1 REPLY 1

sunil_m_l10
Tera Expert

Hi @community Alums 
I'm trying to set the Destination stockroom based item category with the below code

 

 

_populateTransferOrderInfo: function(item) {

//Set the destination stockroom based on the item category
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.get(item.sys_id);
var deliverToSite = ritmGR.cat_item.category.toString();
var stockGR = new GlideRecord('alm_stockroom');
if (deliverToSite == '1ed803df332d9210ce6f72d24d5c7be6') {
stockGR.get('c5d0f922978fd6d03408f017f053afbd');
var destStockroom = {};
destStockroom['value'] = stockGR.getValue('sys_id');
destStockroom['displayValue'] = stockGR.getValue('name');
//item.destDefault.transfer = JSON.stringify(destStockroom);
item.destDefault.purchase = JSON.stringify(destStockroom);
gs.info('#dest stockroom is ' + item.destDefault.purchase + ' ' + JSON.stringify(destStockroom));
return item;
}
},


log is getting printing in log table but its not setting destination stockroom on purchase order.
what could be the issue