check the string length
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 04:58 AM
hi, i have a problem, i have this function in the client script and in the second if
i want that if the condition is true I call the getReport () function which as input must have its own sys_id,
otherwise I print a paragraph on the screen that says "select a field" how do I do?
below the client and the script server
//Client
function init(){
if(!!c.data.report && c.data.report.length){
getReport(c.data.report);
}
else{
var objToSend = {
action: c.data.EVENTS.getUserPreferences,
report_sys_id: c.data.report
};
c.server.get(objToSend).then(function(response){
if(response.data.prefReport.length){
getReport();
}else{
//create div that say 'select a value'
}
});
}
}
//Server script
function getReport(input){
try{
var reportGR = new GlideRecordSecure('sys_report');
reportGR.addQuery('sys_id', data.report);
reportGR.query();
if(reportGR.hasNext()){
$sp.log('reportGR: ' + reportGR.title);
}
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('/api/now/table/sys_report?sysparm_query=sys_id%3D' + input.report_sys_id);
request.setHttpMethod('GET');
request.setRequestHeader('Accept','application/json');
request.setRequestHeader('Content-Type','application/json');
request.setRequestHeader('X-UserToken', input.g_ck);
//request.setRequestHeader('X-UserToken', token);
var response = request.execute();
$sp.log('report: ' + response.getBody());
data.reportResponse = response;
}
catch(e){
$sp.log("error in getReport: " + e);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 05:36 AM
Pls try following.
response.data.prefReport.toString().length
Thanks
Harshad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 06:02 AM
is already a string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 07:36 AM
i guess if statement is expecting some true value.
if(response.data.prefReport.length>1) or something? Can you add some evaluation there?
Thanks
Harshad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 08:50 AM
yes, the data.prefReport variable is initialized as an empty string.
data.prefReport = '';
and I'm checking if the string is not empty you call me the getReport () function which as a parameter must take the sys_id,
otherwise you write me a paragraph or a div in the page that tells me 'select a field'