Estimate Page Customisation

Jira Code: CN-7
Add a button on estimate page to open the new ‘Project’ page auto-populated with Client Name, Estimate Name and Estimate number.

User Event Script: CN-7 JJ UE Estimate Customisation

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
/*******************************************************************************
* CLIENTNAME:C2 NATIVE
* CN-7
* Estimate Page Customisation
* **************************************************************************
* Date : 31-08-2018
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This script is to add ‘Create Project’ Button and actions on clicking the Create Project button the new Project page will be open.
* Date created : 31-08-2018
*
* REVISION HISTORY
*
* Revision 1.0 ${date} nd : created
* Revision 1.1 ${date} nd : updated
*
******************************************************************************/
define(['N/record','N/search'],

function(record,search) {
   
    /**
     * 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) {
    	try{
    		 var estimate =  scriptContext.form;
    		 var estimateRecordId = scriptContext.newRecord.id;
            //adding button
           	 
           	 var button = estimate.addButton({
        		id: 'custpage_project',
        		label :'Create Project',
        		 functionName: 'buttonClick'
        	 });

           	 scriptContext.form.clientScriptFileId = 3117;
    		 if(scriptContext.type !=  'create'){
    			 if(scriptContext.type == 'view'){
    				 var salesorderSearchObj = search.create({
    					   type: "salesorder",
    					   filters:
    					   [
    					      ["type","anyof","SalesOrd"], 
    					      "AND", 
    					      ["mainline","is","T"], 
    					      "AND", 
    					      ["createdfrom.internalidnumber","equalto",estimateRecordId]
    					   ],
    					   columns:
    					   [
    					      search.createColumn({name: "entity", label: "Name"}),
		     
    					   ]
    					});
    				 var searchResult = salesorderSearchObj.run().getRange({
    	               		start:0,
    	               		end:100
    	               	});
    				
    				 if(searchResult == ''){
    					 button.isDisabled = true;
    				 }
    			 }
    		 }
    		 else if((scriptContext.type == 'edit') || (scriptContext.type == 'create')){
    			 button.isDisabled = true;
    		 }
         
        	
        	 
        	 
    	}catch(e){
    		log.error('error',e)
    	}		
    	

    }

   
    return {
        beforeLoad: beforeLoad,
        
    };
    
});

Leave a comment

Your email address will not be published. Required fields are marked *