locked
Update all records to run javascript RRS feed

  • Question

  • Hi all,

    I've written some Javascript so that when a new organisation is added to the CRM the local area will be entered into a field depending on the postcode.  This works fine when adding new records but is there a way to get all of the organisations that are already in the CRM to run this code?

    Thanks.
    Friday, October 26, 2012 3:16 PM

Answers

  • As you probably already figured out JavaScript will only run when the record is actively open in the browser. 

    A couple options:

    Use Advanced Find, query on postcode and bulk update the resulting records.

    Create a workflow the replicates the logic of the JavaScript that can be run on demand and run it against the existing records. 

    Create an application using the SDK to programmatically update the records using similar logic. 


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, October 26, 2012 3:30 PM
    Moderator

All replies

  • As you probably already figured out JavaScript will only run when the record is actively open in the browser. 

    A couple options:

    Use Advanced Find, query on postcode and bulk update the resulting records.

    Create a workflow the replicates the logic of the JavaScript that can be run on demand and run it against the existing records. 

    Create an application using the SDK to programmatically update the records using similar logic. 


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, October 26, 2012 3:30 PM
    Moderator
  • Hi,

    another option:

    create a plugin that updates this field when an entity record is created. Create a solution and add this plugin to your solution. Import the solution to all your organizations. In this way, the field will be updated each time a new record of the entity is created (either manually or through import etc.). And through the solution, your code will be portable across multiple organizations.

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    Friday, October 26, 2012 3:52 PM
  • As you probably already figured out JavaScript will only run when the record is actively open in the browser. 

    A couple options:

    Use Advanced Find, query on postcode and bulk update the resulting records.

    Create a workflow the replicates the logic of the JavaScript that can be run on demand and run it against the existing records. 

    Create an application using the SDK to programmatically update the records using similar logic. 


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn


    How would you bulk update them through advanced find???

    Thanks.
    Monday, October 29, 2012 10:40 AM
  • Assuming you have the Bulk Edit permission...

    Do your Advanced Find (where your new value  Does Not Contain Data) - click the check box at the top of the column to select all records in the view.

    Select Edit from the top ribbon

    Update value(s) and save

    Repeat until all records have been updated


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Monday, October 29, 2012 11:10 AM
    Moderator
  • Ah ok, that still won't trigger the javascript so that's not an option unfortunately.

    Thanks anyway.

    Monday, October 29, 2012 1:30 PM
  • Hi,

    if you want to use JavaScript for this, you can add a Ribbon Button to the entity and call your JavaScript function there. In this case though, you would have to use the REST Endpoint in JS in order to update all the records that are selected in the grid. Through the ribbon button you can get the Ids of the selected records passed as a parameter to your function. Then you can use these Ids to update the records.

    Keep in mind though that if many records are selected, it may take some time until they are all updated.

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    Monday, October 29, 2012 1:45 PM
  • Hi,

    Yes, that's what I need.  I understand adding a ribbon button etc. but can you explain what the REST Endpoint is?  I've never heard of it...

    Thanks!

    Monday, October 29, 2012 2:58 PM
  • Hi,

    the REST endpoint is a web service you can use to perform CRUD operations on Dynamics CRM entity records. You can find samples on how to use it in JavaScript here and here.

    Check it out and try to implement a simple JS function to update a CRM record.

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    Monday, October 29, 2012 3:04 PM
  • Seems a bit complex, not sure if it's worth the hassle.

    Thanks anyway!
    Monday, October 29, 2012 3:13 PM