Hi, I have written Client Script on custom record ...
# suitescript
m
Hi, I have written Client Script on custom record type it is working fine while editing or initially page loading but it is not working on Record View Page. any clue
g
for view mode, use UserEvent script beforeload
s
Curentrecord on view mode only gives id and type
m
so what do i need to use to get the detail of the record
s
is the record in edit or create mode?
m
no in view mode
s
you use the "N/currentRecord" to get the id and type then use "N/record" record. load the data. (this was @battk idea )
m
That's good idea,
one more thing i want to ask
s
sure
m
I have written a script can you review what's wrong with this code it is working on script deployment Testing but it's not working on release mode.
s
i can try
m
/**
* @NApiVersion 2.x * @NScriptType ClientScript */ // In SuiteScript 2.0 define(['N/search', 'N/currentRecord', 'N/ui/dialog'], function(search, currentRecord, dialog) { return { pageInit: function(context) { var currentRecord = context.currentRecord; var custRecordValue = currentRecord.getText({ fieldId: 'custrecord11' }); var color = getColor(custRecordValue.trim()); var elem = document.getElementsByClassName('uir-page-title-secondline')[0].innerHTML; var elem = elem + '<div class="uir-record-status" style="background-color:'+color+'">'+ custRecordValue +'</div>'; document.getElementsByClassName('uir-page-title-secondline')[0].innerHTML = elem; }, fieldChanged: function(context){ var currentRecord = context.currentRecord; if(context.fieldId == 'custrecord11'){ var valueOfStatus = currentRecord.getValue({ fieldId: 'custrecord11' }); var custRecordValue = currentRecord.getText({ fieldId: 'custrecord11' }); elem = document.getElementsByClassName('uir-record-status')[0]; elem.innerHTML = custRecordValue; elem.style.backgroundColor = getColor(custRecordValue.trim()); //dialog.alert({ // title: 'Status Change', // message: 'Status has changed to ' + custRecordValue //}); } } }; function getColor(stats){ return stats == 'Pending Approval' ? 'orange' : stats == 'Need 1st Level Approval' ? 'yellow' : stats == 'Need 2nd Level Approval' ? 'blue' : stats == 'Approved' ? 'green' : stats == 'Rejected' ? 'red' : '#D5E0EC'; } });
do you think i can play with the HTML in userscript
s
dont think so
m
This is what I did using above script but I do not know how useful is this but it is working fine