How to check view in business rule

ritaaudi
Tera Contributor

Hi: I have a business rule that I only want to run on a specific view. Anyone know how to do a view check in a business rule? Thanks! Rita

7 REPLIES 7

Abhinay Erra
Giga Sage

Rita,



      Business rules are not linked to the form, So there is no Out of Box functionality that can get you a view in a business rule. But you can go through this thread, you will find a work around.


How do I get name of the view that submitted the form inside a business rule




Thanks,


Abhinay




PS: Hit like, Helpful or Correct depending on the impact of the response


rajeevlochan82
Mega Guru

Hi Rita,



As stated by Abhinay Business Rules are not view specific but you can do few tricks.



1) View run on View rules so the type of condition you have specified in View Rules you can check for same conditions and if they are true run your business rule.



2) You can use DOM to look for view name and if found run your Business Rule.



find_real_file.png



Thanks ,


Rajeev



PS: Hit like, Helpful or Correct depending on the impact of the response


Abhinandan Pati
Giga Guru

Hi Rita,



Below code snippet should help you



var view_name='';


if (gs.getSession().isInteractive()) {


      var map = gs.action.getGlideURI().getMap();


      if (map.get('sysparm_view') != null) {


      view_name= map.get('sysparm_view').toString();


      }


  }


gs.log('View: '+view_name);



Thanks


Abhinandan


Hi Abhinandan: Your code worked beautifully in the business rule! I also want to change the view in the business rule to blank after the lookup. I tried:


map.set('sysparm_view', '');


but that didn't seem to work. Any idea?


Thank you all! Rita