11
Points
Questions
1
Answers
4
-
window.opener not working in SuiteScript 2.0
Scenario
Using SuiteScript 2.0, the native Javascript window.opener does not function as it did in SuiteScript 1.0
Solution
Invoke the function by referring to a module in the require statement.Sample:window.opener.require([‘/SuiteScripts/Test/ps_test_client’], function(myModule) {myModule.setTestField(field1);})Check the “Supply Chain Management” suiteapp (Item substitution function) to see a working example how its working in SS2.0- 1113 views
- 2 answers
- 0 votes
-
Maybe Im wrong, but I think you always have to use the pageInit function… Try to include it
/**/*** @NApiVersion 2.x* @NScriptType ClientScript* @NModuleScope SameAccount*/define([‘N/ui/dialog’,’N/record’,’N/log’],function(dialog,record,log) {function pageInit(context) {
//nothing to do
}
function fieldChanged(context) {var currentRecord = context.currentRecord;var sublistid = context.sublistId;if(fieldChanged.fieldId ==’entity’){var name = currentRecord.getCurrentSublistValue({sublistId: ‘line’,fieldId: ‘entity’});// dialog.alert({// title:’name:’,// message: name// })if(name==record.Type.EMPLOYEE){currentRecord.setCurrentSublistValue({sublistId:’line’,fieldId:’custcol_ks_recordtype’,value:’Employee’});console.log(name)}if(name==record.Type.CUSTOMER){currentRecord.setCurrentSublistValue({sublistId:’line’,fieldId:’custcol_ks_recordtype’,value:’Customer’});}if(name==record.Type.VENDOR){currentRecord.setCurrentSublistValue({sublistId:’line’,fieldId:’custcol_ks_recordtype’,value:’Vendor’});}dialog.alert({title:’name:’,message: name})}}return {pageInit: pageInit,fieldChanged: fieldChanged}});- 514 views
- 1 answers
- 0 votes
-
Here is an example – not tested
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define([‘N/https’, ‘N/record’, ‘N/redirect’, ‘N/ui/serverWidget’, ‘N/search’, ‘N/log’, ‘N/runtime’],function( https, record, redirect, serverWidget, search, myLog, runtime ){
function onRequest(context) {
var request = context.request;
var response = context.response;if (request.method == ‘GET’) {
var getFilter = request.parameters.filter; //After the client script fieldchanged (Redirect) this parameter will be available
var form = serverWidget.createForm({
title: ‘Your Titel’
});form.clientScriptFileId = yourFileId; //Attach your client script to the suitelet
var filter = form.addField({
id : ‘filter’,
type : serverWidget.FieldType.TEXT,
label : ‘filter’
});if (getFilter){ //if getFilter has a value then set defaultValue
filter.defaultValue = getFilter;
}/* Use a saved search….
…
…
…
context.response.writePage(form);
} else {
// POST method
}
}return {
onRequest: onRequest
};
});/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define([‘N/record’, ‘N/ui/dialog’, ‘N/search’, ‘N/ui/message’, ‘N/url’], function(record, dialog, search, message, url) {function pageInit(scriptContext) {
//do something
}
function changeFilter(scriptContext) {
if (scriptContext.fieldId == ‘filter’){var currentRecord = scriptContext.currentRecord;
var currentUrl = document.location.href;
var urls = new URL(currentUrl);var getFilter = currentRecord.getValue({ //gets value from the Suitelet filter field
fieldId: “filter”
});window.onbeforeunload = null;
window.location.replace(urls+’&filer=’+getFilter);}
}
return {
pageInit: pageInit,
fieldChanged: changeFilter
};
});- 2735 views
- 3 answers
- 0 votes
-
Attach a client script to your suitelet and use the fieldChanged function to redirect to the suitelet with different parameters.
use window.onbeforeunload = null; – to get rid of the “changes may not get saved” message (or something like this)
- 2735 views
- 3 answers
- 0 votes