質問

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.

役に立ちましたか?

解決

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());
     });
}
ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top