/**
* Set PeoplePicker Field(2007 or 2010 Style, Calendar/Event Form ) value
* @param {string} FieldDisplayName
* @param {string} FieldValue
* @return {boolean}
*/
function setPeoplePickerName(FieldDisplayName, FieldValue){

var searchText = RegExp(“FieldName=\”” + FieldDisplayName + “\””, “gi”);

$(“.ms-formbody”).each(function() {
//$(“span.fieldValueSpan”).parent().each(function() {
if(searchText.test($(this).html())) {
//alert(“found”);
//alert($(this).find(“div[Title=’People Picker’]”).length);
if($(this).find(“div[Title=’People Picker’]”).length > 0){
$(this).find(“div[Title=’People Picker’]”).html(FieldValue);
$(this).find(“div[Title=’People Picker’]”).val(FieldValue);
}
else{ //after SharePoint 2018 April CU, the people picker structure have been changed
$(this).find(“div[Title='”+ FieldDisplayName +”‘]”).html(FieldValue);
}
//$(this).find(“a[Title=’Check Names’]”).click();
return true;
}
});

return false;
}

Advertisements

let’s use below, before ajax REST call

UpdateFormDigest(_spPageContextInfo.webServerRelativeUrl, _spFormDigestRefreshInterval)

 

reference : http://www.wictorwilen.se/sharepoint-2013-how-to-refresh-the-request-digest-value-in-javascript

 

other thing…to know ^^

SharePoint 2013 supports the abbreviation “_api” as a substitute for “_vti_bin/client.svc.”
This is the base URL for every endpoint: http://<domain>/<site url>/_api/

Some blog said when we update multiple selection checkboxes from SharePoint 2013 workflow, recommend to use delimiter(;#) but it’s not working. delimiter(,) not working either.

Example: [choice value1];#[choice value2];#[choice value3] not working

Example: [choice value1],[choice value2],[choice value3] not working

 

Solution) Use Json format field value settings.

Example)

Create String type workflow local variable named “MultiChoiceValues”. I tried dictionary type variable but when publishing the workflow, type error occurred.

Set Variable:MultiChoiceValues to Current Item:MultipleCheckBoxesField

  • You should select ‘Return field as’ choice as ‘As String’ not ‘Choices, Comma Delimited’ (important)
  • The workflow local variable has below format of strings
  • {“__metadata”:{“type”:”Collection(Edm.String)”},”results”:[“Choice Value 1″,”Choice Value 2″,”Choice Value 3”]}

If Variable: MultiChoiceValues contains [Choice Value 1]

Replace [Choice Value 1] with [Choice Value 9] in Variable: MultiChoiceValues (Output to Variable: MultiChoiceValues)

Set MultipleCheckBoxesField to Variable: MultiChoiceValues

 

 

I have to tick ‘All Day Event’ check box for SharePoint Calendar Event input form.
So add below code into new form


$(document).ready(function () {

var $checkBoxAllDayEvent = $("span[title='All Day Event']> input");
if( $checkBoxAllDayEvent.length > 0){

//instead setting the box checked, better to call the click event
if( !$checkBoxAllDayEvent.attr("checked") ){
$checkBoxAllDayEvent.click();
}
}
});

At the beginning it works fine but when I un-tick the check box again, it reload the form again and then the script loaded again so there is no way to un-tick the check box.
So I need to check whether this form is from postback or not but I can’t find any internal SharePoint javascript variable or function to check postback.

So the only way is check document.referrer and document.location.href.


$(document).ready(function () {
if( document.referrer != document.location.href )
{
var $checkBoxAllDayEvent = $("span[title='All Day Event']> input");
if( $checkBoxAllDayEvent.length > 0){

//instead setting the box checked, better to call the click event
if( !$checkBoxAllDayEvent.attr("checked") ){
$checkBoxAllDayEvent.click();
}
}
}
});

Method 1)

/**
* @class ObjItem
* @type {Object}
* @property {id}
* @property {title}
* @property {startDay}
* @property {category}
*/
function ObjItem(id, title, startDay, category){
this.id = id;
this.title = title;
this.startDay = startDay;
this.category = category;
}


var myItem = new ObjItem(1, "Test Title", "2017-10-04", "Holiday");

Method 2)

/**
* @class ObjItem
* @type {Object}
* @property {id}
* @property {title}
* @property {startDay}
* @property {category}
*/
function makeObjItem(id, title, startDay, category){
var obj = {
id: id,
title: title,
startDay: startDay,
category: category
};
return obj;
}


var myItem = makeObjItem(1, "Test Title", "2017-10-04", "Holiday");

Reference from :
https://stackoverflow.com/questions/12272239/javascript-function-returning-an-object
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes