Calling form’s JavaScript functions in ISV.CONFIG


Hi,

We had a requirement to check for user’s role on click of one of the isv.config button. So we thought of using JavaScript attribute of the button.

This is one of the very good article about how to use javascript for checking the roles

http://jianwang.blogspot.com/2008/01/crm-40-check-current-users-security.html

However using JavaScript within ISV.Config has its own share of trouble as it is an xml file, so we need to replace so many characters within it and moreover this has to be done very carefully.

So what we decided that we’d put the JavaScript code in the entity’s form’s onload event and would simply call that function within isv.config, than we wouldn’t have to replace characters within JavaScript for making them xml specific.

So suppose this is the JavaScript function

function UserHasRole(roleName)
{
 //get Current User Roles, oXml is an object
 var oXml = GetCurrentUserRoles();
 if(oXml != null)
 {
  //select the node text
  var roles = oXml.selectNodes("//BusinessEntity/q1:name");
  if(roles != null)
  {
   for( i = 0; i < roles.length; i++)
   {
    if(roles[i].text == roleName)
    {
     //return true if user has this role
     return true;
    }
   }
  }
 }
 //otherwise return false
 return false;
}

 

Now to make it reusable, so that we could call it within isv.config we just need to change its declaration

from

function UserHasRole(roleName)

{

// function body

}

to

UserHasRole=function(roleName)

{

// function body

}

and put it in the form’s onload event javascript.

And to call it within Button’s JavaScript –>

UserHasRole(‘System Administrator’)

Just like a normal function !!

 

Bye…


Discover more from Nishant Rana's Weblog

Subscribe to get the latest posts sent to your email.

Unknown's avatar

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

8 thoughts on “Calling form’s JavaScript functions in ISV.CONFIG”

  1. Hi Nishant Rana

    i am so sorry to post this here and sorry to trouble you.

    I am Zhongchen Zhou from China and I am currently in Australia and working on MS Dynamics CRM 4 in an company called QA Software, and I am planning to take certification exams. I read your post and I am wondering that Can you please send me eBooks.

    Thanks for your sharing and i will really appreciate it

    zzhou@qa-software.com

    Thanks again

    Like

    1. Hi Viral,
      If the function is declared\defined in this manner in form load

      UserHasRole=function(roleName)
      {

      // function body

      }

      Than you could call the function within the isv.config button for that form, the way you would call a normal function like

      UserHasRole();

      I hope i am clear this time !!! 🙂

      Like

    1. This helps if the buttons are in the form. But if the buttons are in the main window, it will not have onload/onsave methods. So we have to write them in ISV.Config iteslf.

      Any alternatives?

      Like

Leave a reply to Rameswar Datt Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Nishant Rana's Weblog

Subscribe now to keep reading and get access to the full archive.

Continue reading

Power Platform Puzzles

D365 CRM, Power Platform Tips &Tricks

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Microsoft Business Applications Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog - PPUG.ORG

AI - Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue

The Professional Paraphraser

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

Power Platform Learning

Your Go-To Resource for Power Apps, Power Automate & More

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.