getting Modified and Created Field value

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
Hatice Togrul Gürol
Posts: 24
Joined: Thu Nov 13, 2014

18 Nov 2014

hi Dmitry,

I need created and Modified field value.
ı found a code block that you mentioned. But this code returns only Editor and Author field values.
İs it possible to get date field value with the same code.
SP.SOD.executeOrDelayUntilScriptLoaded((function () {
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getById(_spPageContextInfo.pageListId);
var item = list.getItemById(parseInt(GetUrlKeyValue('ID')));
ctx.load(item);
ctx.executeQueryAsync(function() {
alert('Author: ' +
item.get_item('Author').get_lookupId() +
' - ' +
item.get_item('Author').get_lookupValue() +
'\nEditor: ' +
item.get_item('Editor').get_lookupId() +
' - ' +
item.get_item('Editor').get_lookupValue());
});
}), "SP.js");

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

18 Nov 2014

Hi,

Please, use the following code:

Code: Select all

SP.SOD.executeOrDelayUntilScriptLoaded((function () { 
	var ctx = new SP.ClientContext.get_current();
	var list = ctx.get_web().get_lists().getById(_spPageContextInfo.pageListId);
	var item = list.getItemById(parseInt(GetUrlKeyValue('ID')));
	ctx.load(item);
	ctx.executeQueryAsync(function() {
		alert('Modified: ' +
			item.get_item('Modified') + 
			'\nCreated: ' +
			item.get_item('Created'));
	});
}), "SP.js");
If you need to output these values on the form, you can put a plain text control with the following content instead:

Created: [Created]
Modified: [Modified]

User avatar
Hatice Togrul Gürol
Posts: 24
Joined: Thu Nov 13, 2014

18 Nov 2014

I have added the code that you mentioned but alert shows not a good date format .

the screen like this;

Modifed: Mon nov 17 13:40:46 UTC +0200 2014


I want to show like this date format;

Created at 17.11.2014 13:40

Last Modified at 17.11.2014 13:40


I don't want to use default [Created] or [Modified] field.

I need to assign my own to a field that is using this codes.

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

19 Nov 2014

Hi,

You can use additional JavaScript library to format date objects, e.g datejs, date.format. With datejs your code will look something like that:

Code: Select all

SP.SOD.executeOrDelayUntilScriptLoaded((function () { 
	var ctx = new SP.ClientContext.get_current();
	var list = ctx.get_web().get_lists().getById(_spPageContextInfo.pageListId);
	var item = list.getItemById(parseInt(GetUrlKeyValue('ID')));
	ctx.load(item);
	ctx.executeQueryAsync(function() {
		alert('Modified: ' +
			item.get_item('Modified').toString('dd.MM.yyyy HH:mm') + 
			'\nCreated: ' +
			item.get_item('Created').toString('dd.MM.yyyy HH:mm'));
	});
}), "SP.js");

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests