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 :
Service | Customer Service, Contact Center, Fie...
Answered

Field problem Javascript form

(0) ShareShare
ReportReport
Posted on by 411

Hello everyone,
Can someone help me please with this code : 

function setValue(executionContext)

{
var formContext = executionContext.getFormContext();
var url = formContext.getAttribute("new_urlducrm").getValue();
if (null !=url) {
var test = url.split("=").pop().replace('"','');
formContext.getAttribute("new_iddelopportunite").setValue(test);

}
}

I want to modify it to clear the new_iddelopportunite field when the content of the "new_urlducrm" is deleted. 
exemple : 

pastedimage1606775642218v1.png

and now i delete the content of url du CRM but id de l'opportunité still display informations 

pastedimage1606775704460v2.png

The second point is , actually this function take this url model :  alloresto.crm4.dynamics.com/main.aspx

and paste everything after "&id=" and paste it in ID de l'opportunité field : de4ddcf6-1494-41e5-8907-3279299ac8dc

But like you see it doesnt take everything after "id=" because it miss &ForceU=1131
The correct function would have paste this : de4ddcf6-1494-41e5-8907-3279299ac8dc&ForceU=1131

If Leah Ju see this, i'm sure you can help me ^^ , you're the best ;)

Cordially

I have the same question (0)
  • Piyush Paliwal Profile Picture
    817 on at

    Hi,

    Dymamics 365 already gives you methods to extract ID of any Table/Entity (see here), and to open a record via URL (see here). Can you maybe detail out the functional requirement instead of technical explanation?

    The reason why I ask this is because for the most part you might not need this entire code, your problem could be resolved by just utilizing the client api methods. It would be great if you provide the functional context.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Archetype,

    1.you can use following js code to achieve that you want.

    function setId(executionContext) 
    {
        var formContext = executionContext.getFormContext();
        var url = formContext.getAttribute("new_url").getValue();
        if(url!=null)
        {
        var id =  url.split("&id=").pop();//get id you need
        formContext.getAttribute("new_id").setValue(id);
        }
        else
        formContext.getAttribute("new_id").setValue(null);//clear id field value when url is empty
    }

    2.Add js to web resource.

    pastedimage1606801247331v1.png

    3.Add it to url field OnChange event.

    pastedimage1606801304804v2.png

    4.Test.

    (1) fill url field:

    pastedimage1606801317058v3.png

    (2) clear url field:

    pastedimage1606801403895v4.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Archetype Profile Picture
    411 on at
    [quote user="Leah Ju"]

    Hi Archetype,

    1.you can use following js code to achieve that you want.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    function setId(executionContext)
    {
    var formContext = executionContext.getFormContext();
    var url = formContext.getAttribute("new_url").getValue();
    if(url!=null)
    {
    var id = url.split("&id=").pop();//get id you need
    formContext.getAttribute("new_id").setValue(id);
    }
    else
    formContext.getAttribute("new_id").setValue(null);//clear id field value when url is empty
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    2.Add js to web resource.

    pastedimage1606801247331v1.png

    3.Add it to url field OnChange event.

    pastedimage1606801304804v2.png

    4.Test.

    (1) fill url field:

    pastedimage1606801317058v3.png

    (2) clear url field:

    pastedimage1606801403895v4.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

    [/quote]

    Thanks you very much Leah Ju <3

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 55 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 27 Most Valuable Professional

#3
Scott Jackson UK Profile Picture

Scott Jackson UK 22

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans