getting Modified and Created Field value
Posted by Hatice Togrul Gürol - Nov 18 ’14 at 03:54
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");
-
Dmitry KozlovAdminMember for: 8 years 7 months 25 days
Hi,
Please, use the following 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('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] -
Hatice Togrul GürolMemberMember for: 7 years 5 months 29 days
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.
-
Dmitry KozlovAdminMember for: 8 years 7 months 25 days
[#2]: 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:
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");