- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 11:45 PM
Hi everyone,
I have a requirement to hide a value of a reference field, if the users department starts with BT.
I have written the Script Include below:
Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 11:50 PM - edited 11-21-2024 11:54 PM
try:
javascript: new getUserDetails().getFilter(gs.getUserID())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 03:53 AM - edited 11-22-2024 03:55 AM
Hello @xhensilahad ,
You should uncheck the client callable option and use below code to call script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 07:09 AM
I wouldn't worry too much about other system logs - you can drive yourself mad reading through all of that and it's likely unrelated. You're getting the correct substring, so I guess we need to take this one step further to confirm what is being returned to the qualifier. And be sure to test both cases - so you should see this department name with this test case
var getUserDetails = Class.create();
getUserDetails.prototype = {
initialize: function() {},
getFilter: function(userID) {
var userGR = new GlideRecord('sys_user');
if (userGR.get(userID)) {
var department = userGR.department.name.toString();
if (department && department.substring(0, 2) === 'BT') {
gs.addInfoMessage('SI inside if');
return 'active=true';
} else {
gs.addInfoMessage('SI else');
return 'active=true^name!=IT Infrastuktur';
}
}
}
};
Then, if a non-BT... department user logs correctly in the else block, but still sees the department, hard-code the qualifier
active=true^name!=IT Infrastuktur
to see if this is correct. You can manually filter a list view by this criteria to view the correct records, then right-click to copy the query and paste that into the qualifier/script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 05:28 AM
Hi Brad, thank you for your help.
I can see the Info Messages correctly, but there is also an error generated, do you have any idea why that is being generated? Thank you for your help.
Background message, type:info, message: SI running 7d2d3723879706504b5b43730cbb35d6
Unparseable date: "1": java.text.ParseException: Unparseable date: "1": java.base/java.text.DateFormat.parse(DateFormat.java:399) com.snc.commons.datetime.SNCSimpleDateFormatEx.parse(SNCSimpleDateFormatEx.java:133) com.glide.util.SimpleDateFormatEx.parse(SimpleDateFormatEx.java:38) com.glide.glideobject.GlideDate.setValue(GlideDate.java:145) com.glide.glideobject.GlideDateTime.setInitialValue(GlideDateTime.java:1785) com.glide.script.glide_elements.GlideElementGlideObject.setInitialValue(GlideElementGlideObject.java:234) com.glide.script.GlideRecord.loadRow0(GlideRecord.java:3925) com.glide.script.GlideRecord.loadRow(GlideRecord.java:3754) com.glide.script.GlideRecord.next(GlideRecord.java:7080) com.glide.script.GlideRecord.get(GlideRecord.java:1890) com.glide.script.GlideRecord.getFromJS(GlideRecord.java:1847) com.glide.script.GlideRecord.jsFunction_get(GlideRecord.java:1827) jdk.internal.reflect.GeneratedMethodAccessor385.invoke(Unknown Source) java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.base/java.lang.reflect.Method.invoke(Method.java:569) org.mozilla.javascript.MemberBox.invoke(MemberBox.java:151) org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:717) org.mozilla.javascript.FunctionObject.call(FunctionObject.java:654) org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2973) org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1720) org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1030) org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:161) com.glide.caller.gen.sys_script_include_33afdf34874256504b5b43730cbb359c_script.call(Unknown Source) com.glide.script.ScriptCaller.call(ScriptCaller.java:22) org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:160) org.mozilla.javascript.ScriptRuntime.doCall2(ScriptRuntime.java:3058) org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2981) org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1720) org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1030) org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:161) com.glide.caller.gen.null_null_script.call(Unknown Source) com.glide.script.ScriptCaller.call(ScriptCaller.java:22) org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:160) org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:731) org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:4024) org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:173) com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:412) com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:223) com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:141) com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:364) com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:251) com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:230) com.glide.processors.ScriptProcessor.evaluateScript0(ScriptProcessor.java:412) com.glide.processors.ScriptProcessor.lambda$evaluateScriptWithRecordingOption$0(ScriptProcessor.java:395) com.glide.rollback.recording.RollbackRecorder.execute(RollbackRecorder.java:67) com.glide.processors.ScriptProcessor.evaluateScriptWithRecordingOption(ScriptProcessor.java:395) com.glide.processors.ScriptProcessor.evaluateScript(ScriptProcessor.java:375) com.glide.processors.ScriptProcessor.runScript(ScriptProcessor.java:274) com.glide.processors.ScriptProcessor.process(ScriptProcessor.java:232) com.glide.processors.AProcessor.runProcessor(AProcessor.java:762) com.glide.processors.AProcessor.processTransaction(AProcessor.java:313) com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:187) com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:175) com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:58) com.glide.sys.Transaction.run(Transaction.java:2734) com.glide.ui.HTTPTransaction.run(HTTPTransaction.java:35) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) java.base/java.lang.Thread.run(Thread.java:840)
Background message, type:info, message: SI dept BTA
Background message, type:info, message: si dept substring BT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 07:09 AM
I wouldn't worry too much about other system logs - you can drive yourself mad reading through all of that and it's likely unrelated. You're getting the correct substring, so I guess we need to take this one step further to confirm what is being returned to the qualifier. And be sure to test both cases - so you should see this department name with this test case
var getUserDetails = Class.create();
getUserDetails.prototype = {
initialize: function() {},
getFilter: function(userID) {
var userGR = new GlideRecord('sys_user');
if (userGR.get(userID)) {
var department = userGR.department.name.toString();
if (department && department.substring(0, 2) === 'BT') {
gs.addInfoMessage('SI inside if');
return 'active=true';
} else {
gs.addInfoMessage('SI else');
return 'active=true^name!=IT Infrastuktur';
}
}
}
};
Then, if a non-BT... department user logs correctly in the else block, but still sees the department, hard-code the qualifier
active=true^name!=IT Infrastuktur
to see if this is correct. You can manually filter a list view by this criteria to view the correct records, then right-click to copy the query and paste that into the qualifier/script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 07:47 AM
Hey thank you, I followed your advice, and copied the query from the table. My mistake was that query had to be like this : 'u_name!=IT Infrastruktur'.
The field is now hiding as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 03:53 AM - edited 11-22-2024 03:55 AM
Hello @xhensilahad ,
You should uncheck the client callable option and use below code to call script include.