Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

JScript to capture/store variables when custom button is clicked

Posted on by

HI all, 
I have to do something I have not done before, which is on click of an "Activate Account" button, to store certain values on the Account as variables via JavaScript, which are shown below.

  1.   "lastName": "string",
  2.   "firstName": "string",
  3.   "businessphone": "string", 
  4.   "email": "string",  
  5.   "address1": "string",
  6.   "address2": "string",
  7.   "city": "string",
  8.   "state": "string",
  9.   "zipCode": "string",
  10.   "businessName": "string",
  11.   "deepLink": "string",
  12.   "urlPrefix": "string"

    Once the Button is clicked, it needs to be then hidden, and a custom field bf_accountactivatedflag needs to be set to true.

    The "Activate Account" custom button from Ribbon Workbench only shows when Customer Type (bf_customertype_ = 'B2B' (979580001)

    See screenshots below of the UI:

    pastedimage1662580165234v1.png

    pastedimage1662580192900v2.png

    Can anyone share sample code that would achieve the storing of the variables shown above?  I just need some help getting started...

    Thanks in advance!


  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: JScript to capture/store variables when custom button is clicked

    Hi Chrisbra22,

    Why you are intended to use or store these variables using JS> I already told you for this purpose you need to customize the command of Activate button. 

    As per my experience, there are many better ways to fulfil your requirement. You can do it with the below:

    1. Workflow
    2. Power automate
    3. Plugin

    Using these you will achieve the same functionality that you are intending to do with JS.

    You can also do it with JS but it is a complicated way to achieve. Customize the existing Activate button command and all...

    You can call your APIS through

    1. plugins
    2. workflow extensions
    3. power automates

    If I answer your question then please mark it as verified.

    Let me know if I can provide you with more details.

    Thanks
    Regards,

    Abdul Wahab
    Power Platform/Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit
    Linkedin: www.linkedin.com/.../

  • Chrisbra22 Profile Picture
    Chrisbra22 on at
    RE: JScript to capture/store variables when custom button is clicked

    Hi, thanks for the quick response! 

    I have the button created and show/hide logic in place via Ribbon Workbench.  

    All I really need is the code to store the string values for the fields listed when event "button is clicked by user' is achieved.  Is that something you can assist with - i.e., sample code to store values when a button is clicked?  We need to store these values, and then send them via API to another source later.  

    I can worry about the flags later.  Is the Javascript to store variables something you are familiar with?  

    Thanks again!  

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: JScript to capture/store variables when custom button is clicked

    Hi Chrisbra22,

    First, you need to customize the command for this out-of-the-box Activate button. To hide it, you need to add the 'enable rule' with the logic:

    if (bf_accountactivatedflag === true OR bf_customertype_ = 'B2B' (979580001))
        return false;
    else
     return true;

    When the activate button triggers you need to set  bf_accountactivatedflag to true. For that purpose write

    1. workflow on change of status.
      1. add condition when status = active
      2. Update bf_accountactivatedflag  to true
    2. plugin on change of status in pre-update
      1. add condition when status = active
      2. Update bf_accountactivatedflag  to true
    3. similarly, power automate
    4. or even you can use calculate column

    on click of an "Activate Account" button, to store certain values on the Account as variables via JavaScript, which are shown below. For this purpose, you need to customize the out-of-the-box command.

     

    If I answer your question then please mark it as verified.

    Let me know if I can provide you with more details.

    Thanks
    Regards,

    Abdul Wahab
    Power Platform/Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp: 923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit
    Linkedin: www.linkedin.com/.../

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans