Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to restrict a form custom view only on existing records not on new form

Ramu8
Tera Expert

Hi Team,

 

How to restrict a newly created custom view only on existing records not on new Record( form view) on resource form 

1 ACCEPTED SOLUTION

Siddhesh Gawade
Mega Sage

Hello @Ramu8 ,

 

try below code in your view rule script to check if the current record is new or existing based on that you can hide the view.

 

var uri = gs.action.getGlideURI();
        var sysId = uri.get('sys_id');

		if(sysId != '-1'){                 // if the sys_id is not "-1" then the record is existing record.
answer = 'view_name';
		}

 

 

Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.


Regards,

Siddhesh

View solution in original post

6 REPLIES 6

Not applicable

Dr Atul G- LNG
Tera Patron

Hi @Ramu8 

 

What is the use case of same?

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Thanks for quick Response @Dr Atul G- LNG 

 

Actually my requirement is based on logged in user group i need to show different from view for table resource_plan

1.for existing records based on group am able  to show  newly created custom "resource test" form view using view rule below 

(function overrideView(view, is_list) {
    // Add your code here
    var groupSysIdsProperty = gs.getProperty('resourcegroupvalue'); // Replace with your property name

// Check if the property value is not empty
if (groupSysIdsProperty) {
    //if (!current.isNewRecord) {

var groupSysIds = groupSysIdsProperty.split(',');
gs.log(groupSysIds);
// Assuming 'answer' is a global variable
var answer = null; // set the new view to answer

// Check if the user is a member of any group in the array
for (var i = 0; i < groupSysIds.length; i++) {
if (gs.getUser().isMemberOf(groupSysIds[i])) {
answer = "Test Resource"; // change view name
break; // exit loop once a matching group is found
}
}
}

//answer = null;  

})(view, is_list);
 
but

2.For new record the view should be different not the custom view which we used for existing records on resource plan form view please advice

 

Ramu8_1-1705316788244.png

 

 

Damini Sheth
Tera Contributor

Hi,

 you can go through below link:

https://www.servicenow.com/community/developer-forum/view-rule-to-apply-to-new-records-only/m-p/1739...
It will help to solve your query,

 

Please mark this response as correct or helpful if it assisted you with your question.