This topic contains 3 replies, has 0 voices, and was last updated by Godrules500 7 years, 5 months ago.
-
AuthorPosts
-
June 14, 2017 at 6:17 am #18437
Godrules500I am trying to create 2 dropdowns that are dependent upon each other. 1 is department (so they can look up by dept number) another is department description (can look up by dept desc).
What I need:With SuiteScript 2.0 I need to create the dept description dropdown.It doesn’t need to show any options until a subsidiary has been selected.
The first option should always be blank until dept or dept description is selected.
I need to put it right after or below the department.With both being dependent upon each other, I need to not get in an infinite loop in the fieldChanged. So if dept changes desc I don’t need desc to try and change dept, and then dept to change dept desc again (infinite loop of fieldChanged).
(Optional:Would replace the above 2 and what I have) Get the department to be searchable by dept number and description.
(Dreamishly fanciful hope/prayer) Do we have the ability to replace NetSuite’s default dropdown with a completely different one like Select2 ๐
What I have:I have the dept desc dropdown created.
If dept changes it updates dept desc. if dept desc changes it updates dept.Code:
//User Event Script
function beforeLoad(context) { var thisForm = context.form; var deptDesc = thisForm.addField({ id: ‘custpage_dept_desc_test’, label: ‘Department Description Testing’, type: serverWidget.FieldType.SELECT, container: ‘main’, }); var mySearch = search.create({ type: “department”, columns: [“custrecord_osm_department_description”] }); deptDesc.addSelectOption({ value: ” “, text: “-Select an Option-“, isSelected : false }); var myPagedData = mySearch.runPaged(); myPagedData.pageRanges.forEach(function (pageRange) { var myPage = myPagedData.fetch({index: pageRange.index}); myPage.data.forEach(function (result) { var desc = result.getValue(“custrecord_osm_department_description”); var id = result.id; deptDesc.addSelectOption({ value: id, text: desc, isSelected : false }); }); }); } //Client Script
function fieldChanged(context) { var po = context.currentRecord; if(context.fieldId == “custpage_dept_desc_test”) { po.setValue(“department”, po.getValue(“custpage_dept_desc_test”)); } else if(context.fieldId == “department”) { po.setValue(“custpage_dept_desc_test”, po.getValue(“department”)); } }
This is a cached copy. Click here to see the original post. -
June 14, 2017 at 6:24 am #18438
Godrules500I tried getting the code to format better but I could not. I apologize for the terrible format.
-
June 19, 2017 at 2:05 pm #18439
AE Cloud ConsultantsI have found it useful to create a global variable to avoid getting into loops with client side events.
Code:
var ignoreChange = false;
function fieldChanged(context) {
if(ignoreChange){
ignoreChange = false;
return;
}
var po = context.currentRecord;
if (context.fieldId == “custpage_dept_desc_test”) {
po.setValue(“department”, po.getValue(“custpage_dept_desc_test”));
ignoreChange = true;
} else if (context.fieldId == “department”) {
po.setValue(“custpage_dept_desc_test”, po.getValue(“department”));
ignoreChange = true;
}
}
Make sure you make the global variable inside the function you’re passing to define and not outside, otherwise you’ll be declaring it in the truly global scope and you risk naming collisions and manipulation from other scripts. -
June 20, 2017 at 8:29 am #18440
Godrules500Apparently there is an ignoreFieldChange variable. Once I added this, it started.
Code:
po.setValue({ fieldId: fieldId, value: value, ignoreFieldChange: ignoreFieldChange, });
-
AuthorPosts
You must be logged in to reply to this topic.