Suitescript – passing parameters from two different searhces

Hi – I am slowly learning Suitescript and Javascript –  I am running a search of fulfillments, taking the information and pushing that into another script to obtain a custom record internal id.   I then need to go back to the fulfillment record and update the fulfillment record with the id of the custom record.  I am struggling with the functions and passing parameters.

 

/**
*
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define([‘N/record’, ‘N/search’],

function(record, search) {

/*This function runs a search of all fulfillments that have a consigned item
**@returns {string} The id of a new license record
/*

function getfulfillinfo(){

var itemfulfillmentSearchObj = search.create({
type: “itemfulfillment”,
filters:
[
[“type”,”anyof”,”ItemShip”],
“AND”,
[“mainline”,”is”,”F”],
“AND”,
[“item.type”,”anyof”,”InvtPart”],
“AND”,
[“item.custitemmedium”,”noneof”,”94″,”95″],
“AND”,
[“account”,”anyof”,”236″,”239″],
“AND”,
[“createdfrom.type”,”anyof”,”SalesOrd”],
“AND”,
[“itemnumber.custitemnumbereditionconsigned”,”is”,”T”],
“AND”,
[“trandate”,”within”,”03/13/2023″]
],
columns:
[
“transactionname”,
“line”,
“item”,
“serialnumbers”,
search.createColumn({
name: “formulatext”,
formula: “CONCAT(CONCAT(SUBSTR({item.name},INSTR({item.name},’:’)+2),’-‘),{serialnumbers})”
}),
search.createColumn({
name: “custitemnumbereditionconsigned”,
join: “itemNumber”
})
]
});

var fulfillinfo = [];

var searchResult = itemfulfillmentSearchObj.run().getRange({
start: 0,
end: 10
});

searchResult.forEach(function(result) {

obj = {}

obj.Name = result.getValue(‘formulatext’);
obj.Fulfill = result.id;
obj.Fline = result.getValue(‘line’);
fulfillinfo.push(obj)
return true
};

return fulfillinfo;

};

/*This function runs a search of custom record consignment tracker
**@param {array} fulfillinfo – the values from the fulfillment search
**@returns {string} The id of an existing consignment tracker
/*
function getCTid(fulfillinfo){
var customrecordconsignmenttrackerSearchObj = search.create({
type: “customrecordconsignmenttracker”,
filters:
[ –
[“isinactive”,”is”,”F”]
],
columns:
[
“internalid”
]
});

var CTFilter = search.createFilter({
name:’name’,
operator: ‘contains’,
values: CTName
});
customrecordconsignmenttrackerSearchObj.filters.push(CTFilter);

var CTResult = customrecordconsignmenttrackerSearchObj.run().getRange(0,1);

log.debug(‘CTResult’, CTResult);

CTResult.forEach(function(newresult) {

var CTid = newresult.getValue(‘internalid’);

});

return CTid;

};

/*This function updates the fulfillment record with the consignment tracker
**@param {array} fulfillinfo – the values from the fulfillment search, {sring} – CTid the id of the Consignment tracker
/*

function updateFulfill(fulfillinfo,CTid) {

/* {N/record.Record} */

var CTFulfill = record.load({
type: record.Type.ITEM_FULFILLMENT,
id: Fulfill,
isDynamic: true
});

CTFulfill.selectLine({‌
sublistId: ‘item’,
line: CTindex
});

log.debug(‘index’,CTindex);

CTFulfill.setCurrentSublistValue({
sublistId: ‘item’,
fieldId: ‘custcoltranconsignmenttracker’,
line: Fline,
value: CTindex,
ignoreFieldChange: true,
forceSyncSourcing: true

});

CTFulfill.commitLine({‌
sublistId: ‘item’
});

return CTFulfill.save ({
enableSourcing: true
});
};

/**
* Definition of the Scheduled script trigger point.
*
* @param {Object} scriptContext
* @param {string} scriptContext.type – The context in which the script is executed.
* It is one of the values from the scriptContext.InvocationType enum.
* @Since 2015.2
*/

function execute(scriptContext) {

var fulfillsearch = getfulfillinfo();

var Fulfill = ”;
var Fline = ”;
var CTindex = ”;

for (var i = 0; i < resultObj.length; i++) {

Fulfill = resultObj[i].id;
Fline = resultobj[i].getValue(‘line’);
CTindex = CTinfo[0].id;

var CTinfo = getCTid();

var finish = updateFulfill(Fulfill, Fline, CTindex);

};

return {execute: execute};

});

Rookie Asked on March 18, 2023 in SuiteScript.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor