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

  • Archetype Profile Picture
    Archetype 411 on at
    RE: Field problem Javascript form
    [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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Field problem Javascript form

    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.

  • Piyush Paliwal Profile Picture
    Piyush Paliwal 817 on at
    RE: Field problem Javascript form

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans