This topic contains 3 replies, has 0 voices, and was last updated by Mikemacx 7 years, 1 month ago.
-
AuthorPosts
-
October 12, 2017 at 12:58 pm #21454
MikemacxJust a simple question because I'm still getting my feet wet with Suitscript. I made a script to set the bank account on refunds automatically…..
Code:
setRefundAccount()
{
nlapiSetFieldValue('account', 115, null, true);
}
It is set to the form on Page INIT. I just wanted to know, how would it be set up to just set the field once on creating the record and then not reset the field when the record is reopened again? Example: If the field had a different account initially and someone reopened the record and wanted to keep the original field.Thanks
This is a cached copy. Click here to see the original post. -
October 12, 2017 at 1:15 pm #21455
khultquistIt sounds like you've created a Client script, you might want to consider this as a User Event script, which gives you the ability to limit to type=create.
If you want to stick with a client script, there are a couple ways to do what you want. You can check to see if the field is empty, and then set it (see below). Or you could look for another field (something like createdby) that tells you if the record is new.
Code:
setRefundAccount() {
var account = nlapiGetFieldValue('account');
if (!account) nlapiSetFieldValue('account', 115, null, true);
} -
October 12, 2017 at 2:27 pm #21456
pcutlerAs mentioned, you could consider using a user event script as well. But as a client script, just call your function as follows:
function myPageInit(type) {
if(type == 'create') {
setRefundAccount();
}
}
-
October 12, 2017 at 2:34 pm #21457
MikemacxAhhh Yes…….
Code:
function setRefundAccount()
{
var recordid = nlapiGetFieldValue('tranid');
if(recordid == "To Be Generated") { nlapiSetFieldValue('account', 115, null, true);
}
}
Thanks for putting me on the right path…… -
AuthorPosts
You must be logged in to reply to this topic.
