I am using workflow to copy sales order details vi...
# suitescript
p
I am using workflow to copy sales order details via a button but noticed that the subsidiary was not an available field in the Create Record Go To Record action. What I decided to do was create a custom field that has the internal id of the original sales order and then do a search using that id to get the subsidiary. Works great except that the department is now blank. I added that field to my search result thinking I could also populate that field but it does not. Any ideas why?
Copy code
var originalSO = recCurrent.getValue({fieldId: 'custbody_orignal_so'});
            // Create the search for the subsidiary and division
            var s = search.create({
                type: "salesorder",
                filters:
              [
               ["mainline","is","T"], 
               "AND", 
               ["internalid","anyof","45661"]
               ],
                columns:
                [
                    search.createColumn({name: "subsidiary", label: "Subsidiary"}),
                    search.createColumn({name: "department", label: "Division"})
                ]
            });
            var pagedData = s.runPaged({pageSize: 1000});
            for( var i=0; i < pagedData.pageRanges.length; i++ ) {
                var currentPage = pagedData.fetch(i);
                currentPage.data.forEach( function(result) {
                var originalSubsidiary = result.getValue({ name: "subsidiary"});
                var originalDivision = result.getValue({ name: "department"});
                recCurrent.setValue({ fieldId: 'subsidiary',value: originalSubsidiary});            
                recCurrent.setValue({ fieldId: 'department',value: originalDivision});
            });
            }
b
probably want to check that there is a department and that your originalDivision's variable value matches the internal id of that department
p
i did a check using console log and it does match. I do notice though that when the new record is loaded for a split second the field does populate but then the value is removed.
b
p
unfortunately that did not work. i am wondering now if there is another script that is updating that field that I don't know about.
b
potentially
the following works for me
Copy code
require(["N/currentRecord"], function (currentRecord) {
  var salesOrder = currentRecord.get();
  salesOrder.setValue({ fieldId: "subsidiary", value: "4" });
  salesOrder.setValue({ fieldId: "department", value: "2" });
});
p
tried it your way to and same problem. I am almost sure now it's another script doing this. will need to hunt this down. thanks.
b
you can try the
ignoreFieldChange
parameter
g
Also in case you were not familiar, go to customization -> scripting -> scripted records to "hunt down" all scripts impacting a particular record type. Very helpful when I discovered that.
p
thanks Gray. unfortunately the ignoreFieldChange did not work either.