1

Scenario:As per my requirement I need to create a projectrequest form with NEW/Edit/Display. when I click on the add new item ,the new custom input form which is created using the SP DESIGNER 2013 - say projectrequestnewform, should be populated.

Hence, I have created a custom new form using SP Designer 2013 with custom html controls, and other JSOM code for inserting into the splist,validation using jQuery, other js files. Below steps been used to populate the projectrequestnewform form.

  1. Copied the projectrequestnewform into siteasets library of my publishing site collection
  2. Similarly, copied projectrequesteditform && projectrequestdispform into siteasets library
  3. Clicked on the new item from the splist and edit the page and added a content editor web part to give a link to this projectrequestnewform location: /siteassets/projectrequestnewform.html
  4. Also the siteassets library contains the projectrequestnewform.js file that has the JSOM code for CRUD operations on this splist.


when the input form projectrequestnewform.html is loaded on the page, it will be filled with many controls like peoplepicker and dropdowns populated from a SPGroup, Textboxes for entry and having submit,save and cancel functionalities.

when the form's save button is clicked it will simply insert the item into the splist and when submit button is clicked it will finally trigger some approval workflow thats created by SP Wokrflow 2013 Template. This was configured by using SP Designer 2013+ Workflow Manager.


Problem: As part of my reuirement, I also need to apply itemlevelpermissions when this item is inserted/updated. As per my below code,when I applied the itemlevelpermissions feature, permissions got applied to projectrequestnewform.html thats residing in the siteassets library instead of the new item got created in the projectrequest splist.

Also when my event receiver is triggered, I am getting the access denied error such that, i wont be able to add an item into this list.

Question:

  1. I am stuck with how an item added eventreceiver thats targetted to apply the new item in the splist got deviated/applied to the permissions of the the projectrequestnewform.html ?
  2. Does the workflow thats been configured on this SPList's when an item is added , influencing the itemadded() eventhandler ?
  3. can a splistitem would be able to handle both itemadded() eventhandler/receivers and a SP D worflow ?
  4. or my approach of triggering both itemadded/itemupdated() eventreceiver() for applying permissions on the item and trigger an workflow/approval process with multiple tasks simultaneously is NOT ALLOWED as per SharePoint Design ?

Has anyone faced this issue before?

Code:

 public override void ItemUpdated(SPItemEventProperties properties)
    {
        //base.ItemUpdated(properties);


        SPUser currUser = properties.Web.CurrentUser;

        this.EventFiringEnabled = false;

        try
        {

            // if (properties.ListTitle.ToLower() == NPDListNames.ITEMLEVELPERMISSIONSLIST.ToString())
            // {

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                SPSite CurrentSite = new SPSite(properties.SiteId);
                SPWeb CurrentWeb = CurrentSite.OpenWeb(properties.RelativeWebUrl);

                SPList CurrentList = CurrentWeb.Lists[properties.ListId];

                SPListItem CurrentListItem;
                CurrentListItem = 
         CurrentWeb.Lists[properties.ListId].
       GetItemById(properties.ListItem.ID);

  if (!CurrentListItem.HasUniqueRoleAssignments)
                {
                    CurrentListItem.BreakRoleInheritance(true);
                    CurrentWeb.AllowUnsafeUpdates = true;

                    SPRoleAssignmentCollection SPRoleAssColn = CurrentListItem.RoleAssignments;
                    for (int i = SPRoleAssColn.Count - 1; i >= 0; i--)
                    {
                        SPRoleAssignment roleAssignmentSingle = SPRoleAssColn[i];
                        System.Type t = roleAssignmentSingle.Member.GetType();
                        if (t.Name == "SPGroup" || t.Name == "SPUser")
                            SPRoleAssColn.Remove(i);
                    }

custom-new-form-item

  • 2
    what is your question? – Arsalan Adam Khatri Jan 30 '17 at 13:38
  • hello, i have written my question, can you pls help, why my eventreceiver is applying permissions for the customnewform.html file thats residing in the siteassets lib instead of the custom list's new item!! – userAZLogicApps Jan 30 '17 at 13:38
  • @SaMolPP You can refine your question. Filter out unwanted details and throw more light on problem and question. – Asad Refai Jan 31 '17 at 8:41
  • @AsadRefai , i have updated my question with details and code. I am facing this critical issue i my current project. It would be great, If you can help /suggest the approaches ,point me in the right direction, – userAZLogicApps Feb 4 '17 at 15:29
2
+25

please insert a wait condition for 2-3 minutes at the beginning of the designer workflow and check once, so that the code in the event receiver will complete the execution and workflow action will start the after the wait condition. try this and check once

  • the idea about adding a wait condition is seems ok, but somehow i am unable to get it work. – userAZLogicApps Feb 12 '17 at 1:06
0

It is my understanding that both the item added event and the designer workflow will both get fired, not sure though which will get fired first but they are most likely both running at the same time. What might be a better approach, is to not run the sharepoint designer workflow until the item added event has triggered. In the item added event you can then trigger the workflow through CSOM code. Not sure if that helps answer your questions or not.

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.