0

I'm using SP 2013. I have 2 lists, Camps and Activities, that both have a CampID field. The Activities list has a Yes/No field. When I display the edit form for Camps, I need to see if the Yes/No field in Activities for that camp is set to No. If it is, don't display (or disable) some of the fields in the Camps Form. Is there a way to do this without a custom coded solution? I do have SP Designer at my disposal but I'm looking for the simplest solution.

0

You can take inspiration from here: Limit only one entry per day per user in sharepoint list

In short:

  • Display an Activities View on the Edit Form
  • Use JavaScript (in a Calculated Column) to alter your Edit Form
  • I looked through the link but I do not see how this gives me what I need. I had tried another approach I saw that involved creating a calculated column equal to the yes/no column and then making the column a lookup in the Camps list. But that created a dropdown full of Yes and No's, not related to the particular Camp. I don't know how to link the two lists. – John Jun 15 '16 at 19:11
  • Okay, better not continue down this road. Sorry for the red herring – Danny '365CSI' Engelman Jun 15 '16 at 19:19
0

If by "without a custom coded solution", you mean no server-side compiled/deployed code, then yes -- but your solution will almost certainly require some JavaScript code added to the EditForm for your Camps list.

  • First, create a variable to flag whether activities are allowed or no, defaulted to false (e.g. var areActivitiesAllowed = false ) Next, perform a JSOM/CSOM lookup for the corresponding item in the Activities list (see MSDN doc and example)
  • In the onQuerySucceeded, set your areActivitiesAllowed flag to the Yes/No field value from the Item you looked up.
  • Then if the areActivitiesAllowed is true, hook up a jslink template to make a read-only representation of the column:

if (areActivitiesAllowed) {
  fldCtx.Templates = {};
  fldCtx.Templates.OnPostRender = hiddenFieldsOnPostRender;
  fldCtx.Templates.Fields = {
    'InternalNameOfFieldToDisable1': { 'EditForm': makeFieldReadOnly },
    'InternalNameOfFieldToDisable2': { 'EditForm': makeFieldReadOnly },
    'InternalNameOfFieldToDisable3': { 'EditForm': makeFieldReadOnly }
  }
}

function makeFieldReadOnly(ctx) {
    // this is where you would normally return
    // custom field rendering html -- by just returning
    // the plain text value, it is effectively readonly text on the page
    return ctx.CurrentFieldValue;
}

Note: that while this will disable the fields on the page, it is not controlling permissions to those fields. Power users could still write their own CSOM code on their own local machines to edit the apparently disabled fields. Only an EventReceiver (custom code) could truly prohibit the field from being changed by surreptitious means.

  • You could make the javascript a little simpler by adding a "AreActivitiesAllowed" Yes/No field to your Camps list, and then add a short workflow to your Activities list that updates the one in the Camps list. You'd still need to use the above JSLink example to disable the fields when "AreActivitesAllowed" is true, but at least you wouldn't have to use JSOM to look it up first. – willman Jun 15 '16 at 17:21
  • Hi Willman, with regards to your comment, I actually used JQuery in the Activities list to control the display of some fields based on the same Yes/No field that I'm trying to relate to the Camps list. If I could add the Yes/No field to the Camps List, this would be much easier. I'm still not following how to do the JSOM/CSOM lookup even after going through the link. I'm a newbie and any more guidance you could provide would help. It seems like the goal is to get the Yes/no field from Activities that relates to the CampID so I can then create a template (like a view?) based on its value? – John Jun 15 '16 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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