i have a custom field whose value is selected on a...
# ask-stanley-ai
e
i have a custom field whose value is selected on a project template record. When i create a project from that template, the field does not retain its value. How can I make the field retain its value?
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** In NetSuite, when you create a project from a template, the custom fields from the template do not automatically carry over to the new project. This is because the project template and the project are two different record types in NetSuite, and the system does not automatically copy custom field values between different record types. However, you can achieve this by using a User Event Script or a Client Script. Here's a general idea of how you can do it: 1. User Event Script: You can create a User Event Script that triggers on the
afterSubmit
event of the project record. In this script, you can use the
nlapiLoadRecord
function to load the project template record, get the value of the custom field from the template, and then use the
nlapiSubmitField
function to set the value of the custom field on the project record. 2. Client Script: Alternatively, you can create a Client Script that triggers on the
fieldChanged
event of the project record. In this script, you can use the
nlapiGetFieldValue
function to get the value of the custom field from the project template, and then use the
nlapiSetFieldValue
function to set the value of the custom field on the project record. Please note that you will need to replace the function names with the appropriate SuiteScript 2.0 API if you are using SuiteScript 2.0. Here's a sample code snippet for a User Event Script:
Copy code
javascript
function afterSubmit(type){
    if(type == 'create'){
        var projectId = nlapiGetRecordId();
        var projectRecord = nlapiLoadRecord('job', projectId);
        var templateId = projectRecord.getFieldValue('custentity_project_template');
        if(templateId){
            var templateRecord = nlapiLoadRecord('customrecord_project_template', templateId);
            var customFieldValue = templateRecord.getFieldValue('custrecord_custom_field');
            nlapiSubmitField('job', projectId, 'custentity_custom_field', customFieldValue);
        }
    }
}
Remember to replace
'custentity_project_template'
,
'customrecord_project_template'
, and
'custrecord_custom_field'
with your actual field and record IDs. Also, please note that this is a simplified example and you may need to adjust it to fit your specific needs.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.819091797
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.807495177
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.802978575
Please provide your feedback on this answer.