getting Modified and Created Field value

rss

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 Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 24 days
    #1 by Dmitry Kozlov Nov 18 ’14 at 04:59

    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ürol
    Hatice Togrul Gürol
    Member
    Member for: 5 years 26 days
    #2 by Hatice Togrul Gürol Nov 18 ’14 at 07:39

    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 Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 24 days
    #3 by Dmitry Kozlov Nov 19 ’14 at 03:02

    [#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");
    
Displaying 1 to 3 of 3 messages