web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Get accountnumber of account with Javascript and use it in a ribbon buton

(0) ShareShare
ReportReport
Posted on by 40

Hi,

I am not into JavaScript, I'm trying to build a ribbon button in the Account entity form and it should just only open a URL with the accountnumber pasted in the url.

www.url.com/"accountnumber"

var formContext = executionContext.getFormContext();

function openWin(executionContext) {
var accountNumber = "";
accountNumber= executionContext.getAttribute("accountnumber").getValue();
window.open("http://www.url.com/" accountnumber "")
}

This code seems not work, the button itself is working when I only have the javascript

window.open("https://www.google.com")

Any advise, what I'm doing wrong there?

Also the icons I added with Ribbon Benchwork does not show, instead the button ribbon shows a puzzle piece.

Thank you!

Kind regards

I have the same question (0)
  • Esteban Coto Alfaro Profile Picture
    on at

    Hello, you could try this:

    var accountNumber = "";

    accountNumber= executionContext.getAttribute("accountnumber").getValue();

    var windowOptions = {

           openInNewWindow: false, //true

           height: 400,

           width: 400

       };

    var url = "google.com&quot" + accountNumber.toString();

    Xrm.Navigation.openUrl(url, urlOptions);

    I hope it works!

    Thanks!

    Community Support Team - Esteban

    If this Post helps, then please consider Accept as solution to help the other members find it more quickly.

  • david.abax Profile Picture
    40 on at

    Hi,

    sorry did not work.

    Also I tried to another code 

    function openWin(primaryControl) {
    	var formContext = primaryControl.getFormContext();
    	var accountNumer = formContext.getAttribute("accountnumber").getValue();
    	var windowOptions = {
           openInNewWindow: false, //true
           height: 400,
           width: 400
    	};
    	var url = "http://www.google.com""   accountNumber.toString();
    	Xrm.Navigation.openUrl(url, urlOptions);
    }

    This seems also not to work.

  • Verified answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    Hi David,

    Please try below code:

    function openWin(primaryControl) {
        try{
            debugger;
            //var formContext = primaryControl.getFormContext();
            var accountNumber = primaryControl.getAttribute("accountnumber").getValue();
            var windowOptions = {
               openInNewWindow: false, //true
               height: 400,
               width: 400
            };
            var url = "">www.google.com&quot" + accountNumber.toString();
            Xrm.Navigation.openUrl(url, windowOptions);
        }
        catch(e)
        {
            alert(e.message);
        }
    }

    When we pass Primary Control then it contains the FormContext of entity. hence getFormContext() method does not work.
    Hope this help.

    Thanks,
    Pradeep.

    Please mark this as VERIFIED. If it helps.
  • david.abax Profile Picture
    40 on at

    Hi Pradeep,

    thank you, it worked.

    Regards,

    David

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans