Reputation: 23
i want to create a confirmation message in view mode using message.create module i tried in the follwing way as shown in code: first i took a user event script in view mode and added a button in before load and on click of the button a client script is triggered to create the message /** * @NApiVersion 2.x * @NScriptType UserEventScript * @NModuleScope SameAccount */ define(['N/ui/serverWidget'],
function(ui) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type
* @param {Form} scriptContext.form - Current form
* @Since 2015.2
*/
function beforeLoad(scriptContext) {
if (scriptContext.type !== scriptContext.UserEventType.VIEW)
{
log.debug("triggered");
var Form=scriptContext.form;
Form.addButton({
id : 'custpage_message',
label : 'message',
functionName:'message'
});
form.clientScriptFileId = 18249;
}
}
return {
beforeLoad: beforeLoad,
};
}); this is my client script: /** * @NApiVersion 2.x * @NScriptType ClientScript * @NModuleScope SameAccount */ define(['N/ui/message'],
function(message) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
function pageInit(scriptContext) {
}
function message()
{
var myMsg = message.create({
title: "My Title",
message: "My Message",
type: message.Type.CONFIRMATION
});
}
return {
pageInit: pageInit,
message:message
};
});
Upvotes: 0
Views: 2004
Reputation: 226
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/ui/message'],
function(message) {
function pageInit(scriptContext) {
}
function testmessage()
{
debugger;
var myMsg = message.create({
title: "My Title",
message: "My Message",
type: message.Type.CONFIRMATION
});
myMsg.show();
}
return {
pageInit: pageInit,
testmessage:testmessage
};
});
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define([],
function() {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type
* @param {Form} scriptContext.form - Current form
* @Since 2015.2
*/
function beforeLoad(scriptContext) {
if (scriptContext.type == scriptContext.UserEventType.VIEW)
{
log.debug("triggered");
var Form=scriptContext.form;
Form.addButton({
id : 'custpage_message',
label : 'message',
functionName:'testmessage'
});
Form.clientScriptFileId = 115069;
}
}
return {
beforeLoad: beforeLoad
};
});
Upvotes: 0
Reputation: 226
var myMsg = message.create({
title: "My Title",
message: "My Message",
type: message.Type.CONFIRMATION
});
myMsg.show(); -- you missed that statement
-- In User event script
if (scriptContext.type !== scriptContext.UserEventType.VIEW)
{
log.debug("triggered");
var Form=scriptContext.form;
Form.addButton({
id : 'custpage_message',
label : 'message',
functionName:'testmessage()'
});
Form.clientScriptFileId = 115069;
}
as above code view mode but not created because u check the type not equal to view.
Upvotes: 0
Reputation: 226
I Thing Message function Conflicting. Just Rename the message function and try it.
Upvotes: 1