GetItemById in edit form
I use a code block like this in a form:
...
var context = new SP.ClientContext.get_current();
var mainList = context.get_web().get_lists().getByTitle('MyList');
var listItem = mainList.getItemById(1);
context.load(listItem);
context.executeQueryAsync( Function.createDelegate(this, function() {
var title = listItem.get_item('Title')
})
);
...
This works perfect in the display form. In the edit form, I get an error saying that the Title field has not been initialized.
I have tried to load the Title field as part of the context.load() with no success. Network trace shows that the data is correct in the response.
Any suggestions how to solve this?
...
var context = new SP.ClientContext.get_current();
var mainList = context.get_web().get_lists().getByTitle('MyList');
var listItem = mainList.getItemById(1);
context.load(listItem);
context.executeQueryAsync( Function.createDelegate(this, function() {
var title = listItem.get_item('Title')
})
);
...
This works perfect in the display form. In the edit form, I get an error saying that the Title field has not been initialized.
I have tried to load the Title field as part of the context.load() with no success. Network trace shows that the data is correct in the response.
Any suggestions how to solve this?
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
The following core works just fine on all kind of forms:
The following core works just fine on all kind of forms:
Code: Select all
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {
var context = new SP.ClientContext.get_current();
var mainList = context.get_web().get_lists().getByTitle('MyList');
var listItem = mainList.getItemById(1);
context.load(listItem);
context.executeQueryAsync(function() {
var title = listItem.get_item('Title');
alert(title);
});
});
Thank you for the confirmation. Now I got it working.
I startet to confirm that this code worked in a simple form, then I stripped down my complex form and built it up bit by bit. The error was triggered because I had an explicit reference to sp.runtime.js. Maybe multiple references to this file causes trouble...?
I startet to confirm that this code worked in a simple form, then I stripped down my complex form and built it up bit by bit. The error was triggered because I had an explicit reference to sp.runtime.js. Maybe multiple references to this file causes trouble...?
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
To prevent loading the same scripts twice, I'd recommend to use ScriptLink control for out-of-the-box scripts. Put the following code into HTML-control:
Get more information on SharePoint SOD:
http://www.ilovesharepoint.com/2010/08/ ... spsod.html
To prevent loading the same scripts twice, I'd recommend to use ScriptLink control for out-of-the-box scripts. Put the following code into HTML-control:
Code: Select all
<SharePoint:ScriptLink language="javascript" name="sp.runtime.js" Localizable="false" OnDemand="true" runat="server"/>
<SharePoint:ScriptLink language="javascript" name="sp.workflowservices.js" Localizable="false" OnDemand="true" runat="server"/>
And use sp.workflowservices.js following way in JavaScript:
SP.SOD.executeFunc('sp.workflowservices.js', 'SP.WorkflowServices', function() {
// your code here
});
http://www.ilovesharepoint.com/2010/08/ ... spsod.html
-
- Information
-
Who is online
Users browsing this forum: No registered users and 9 guests