I have a page that is using SP.UI.ModalDialog.showModalDialog() to open a NewForm for a list. In the open code I'm passing some values in the args options property as described in this documentation.

The new form is using jslink/client-side rendering to do a couple of things. One of which is assign a choice column if the value has been passed through the arguments.

I've tried both of these lines that I've found in various searches:

args = SP.UI.ModalDialog.get_childDialog().get_args() || {};
args = commonModalDialogGetArguments() || {};

Either one seems to work -- sometimes. Frequently it doesn't return any value. The times it doesn't work I can check in my debugger and if I run the code again or reload the iframe it then works. So I think it is pretty clearly a timing issue.

Edit Additional information

In the csr I've assigned a renderer to a dropdown choice column. The new form can be opened from the regular list (in which case there would be no arguments and the user will need to make a selection) or from my custom page (where the argument is passed). If there is an argument then the custom renderer sets the selected value and makes the drop down disabled.

I had also tried in my custom renderer adding a callback to wait until the body was loaded like this.

var $control = $(getSPField(ctx));
var id = $control.find('select').attr('id');

    var args = commonModalDialogGetArguments() || {};

        var $select = $('[id="'+id+'"]);
}, 'sp.bodyloaded')

return $control.prop('outerHTML');

But even after everything was loaded the choice information passed through the arguments wasn't always available.

How can I wait to render the form until after the arguments are properly passed?

  • What do you mean by "assign a choice column"? You mean set the selected value of a choice column, or show/hide the entire choice column? Also, where in the CSR code are you trying to get the args - in the field rendering, or some other part of the CSR cycle? Mar 6, 2019 at 14:51
  • Thanks for the interest Dylan Cristy. I've edited and added some extra information about the column rendering and what I've tried.
    – Rothrock
    Mar 6, 2019 at 15:53

2 Answers 2


Ok, so after doing some quick research I may have found some options for you. But in general, I've found that when dealing with timing issues with CSR what I have ended up doing is: using the field rendering to just set myself up to be ready for whatever the timing issue dictates will be coming later, and then put off the rest until onPostRender.

For example (and I know I've posted this as an answer somewhere else on this site), if you have to get some other data via AJAX/REST, you could, in the field rendering, just set yourself up some blank divs that have ids you can easily determine in code (for example, including the current item's ID as part of the divs ID), then in onPostRender kick off the AJAX request, then in the callback populate your placeholder divs.

Now in your case the general way I would approach it is:

  • In the field rendering, disable the drop-down (or don't do anything in the field rendering and put it off to happen immediately at the beginning of onPostRender, before you wait for your args).
  • In onPostRender figure out how to get the args, if you get them, set the value and leave it disabled, otherwise enable the drop-down.

Originally I was going to suggest something as brutish as using setTimeout in your onPostRender to wait until you're able to get the args. You'd have to do some testing to see what works reliably, but 10 or 20ms can be a long time in code and negligible to the users.

But - I think I have found something better. First, you mention you have tried SP.UI.ModalDialog.get_childDialog().get_args(). I found this other question/answer here on SP SE that says that in order for that to work you also need to wait until sp.js is loaded, so in your onPostRender you could do something like:

ExecuteOrDelayUntilScriptLoaded(getArgs, "sp.js");

function getArgs(){
    var args = SP.UI.ModalDialog.get_childDialog().get_args();
    // do what you need to do with the args

However, one of the other answers mentions this blog post, which describes getting the args passed to the modal through window.frameElement.dialogArgs.

Now that smells a lot like it might even be available during the field rendering phase of the CSR cycle, but you would have to test that our for yourself.

  • Yes the window.frameElement.dialogArgs is available. I don't even know why someone would bother with either of the SP approaches.
    – Rothrock
    Mar 7, 2019 at 17:21

Are you waiting for the SP library to load? Maybe something like this:

ExecuteOrDelayUntilScriptLoaded(your function name, "sp.js");

Here is a similar discussion: https://social.technet.microsoft.com/Forums/office/en-US/f0e487d1-bf4a-4e86-87f5-b3a61db2ecb7/issue-calling-spuimodaldialogshowmodaldialogoptions?forum=sharepointdevelopmentprevious

  • I can't quite tell from that thread, but it seems the OP was having problems with dialog opening. I'm not having any issue with the dialog opening, just getting the arguments. Also with the csr/jslink I don't think there is any way to wait until things load.
    – Rothrock
    Mar 5, 2019 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.