1

I am writing a code which tests the due date of my task and then the value of my column "emailcheck". This last one is a Yes/No column, by Default set on No, I will need it in to know if I sent or not an email reminder.

However, I am not able to Change the value of this column. I tried several solution, but all failed.

"HERE" in my code is the place where I succeed all the condition and I want to Change the of "emailcheck"

<script type="text/javascript">
function colorCodeRows() {

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
        OnPostRender: function (ctx) {

            // get today's date
            var today = new Date();
            today.setHours(0,0,0,0);

            //In two weeks date
            var twoWeeks = new Date();
            twoWeeks.setDate(today.getDate()+30);
            twoWeeks.setHours(0,0,0,0);

            var rows = ctx.ListData.Row;
            for (var i = 0; i < rows.length; i++) {
                //itemStatus = rows[i][Vorgangsstatus[0].lookupValue];
                //console.log(itemStatus);

                // get the date set in my date field
                var itemDate = new Date(rows[i]['Zieltermin']);
                // zero out the time portion so we only compare days
                itemDate.setHours(0,0,0,0);

                var rowId = GenerateIIDForListItem(ctx, rows[i]);
                var row = document.getElementById(rowId);



                itemEmailCheck = rows[i]["emailcheck"];
                console.log(itemEmailCheck);

                if (itemDate > today && itemDate < twoWeeks) //&& itemStatus != "Completed")
                {
                    row.style.backgroundColor = '#ED9898';

                    if(itemEmailCheck == "Nein")
                    {
                        ////////////////
                        //////HERE//////
                        ////////////////
                    }
                }
            }
        }
    });
}

colorCodeRows();

</script>

I tried this :

function createListitem(){
    var clientContext = new SP.ClientContext(_spPafeContextInfo.siteAbsoluteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Auftragsordner');
    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('emailcheck', 'Ja');
    oListItem.update();
}

I would like a solution to modify this field. Thank you in advance.

3

To set a choice field value, you need to set it as 1 or 0.

Like - oListItem.set_item('emailcheck', 1);

Also, once "updated", you need to execute it using executeQueryAsync to actually send data to the server and add a list item.

Modify your code as below:

function createListitem(){
    var clientContext = new SP.ClientContext(_spPageContextInfo.siteAbsoluteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Auftragsordner');
    var itemCreateInfo = new SP.ListItemCreationInformation();
    var oListItem = oList.getItemById(rows[i]['ID']);
    oListItem.set_item('emailcheck', 1);
    oListItem.update();
    clientContext.executeQueryAsync(function(){
            console.log("Added list item");
     },function(sender, args){
        console.log('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
     });
}
  • Thank you for your reply. However I follow your advise but it doesn't work. I am very new in SharePoint and js, but maybe it should be because there is no concrete ID. But i dont know how retrieve the id of the current row – fullcarton Jun 1 '18 at 12:48
  • can you check with modified code ? – Gautam Sheth Jun 1 '18 at 12:54
  • I just modified var clientContext = new SP.ClientContext.get_current(); and it works perfectly ! – fullcarton Jun 1 '18 at 13:13
  • I maybe saw, I have some code in commentary and it's related to this post link Maybe you know about it. Thank you for your help on this Problem ! – fullcarton Jun 1 '18 at 13:16
  • 1
    Cheers happy to help :) , taking a look at the other question ! Will answer if I find one, but haven't used CSR quite extensively :) – Gautam Sheth Jun 1 '18 at 14:01

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.