最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I set the value of a URL field in the SharePoint 2013 JSOM - Stack Overflow

programmeradmin0浏览0评论

Anyone know how to set the description and url of a URL field in the SharePoint 2013 JSOM? All the field settings examples I've seen use spListItem.set_item(fieldName,fieldValue) which works great for simple fields like text or numbers, but it's failing for me on the plex URL field type. I've tried passing in my URL field name and a ma separated fieldValue = "descriptionText,url"

I've also tried SP.ListItem.parseAndSetFieldValue(fieldname,fieldValue), passing in the URL field name and the ma separated fieldValue = "descriptionText,url".

Am I missing something simple here?

Anyone know how to set the description and url of a URL field in the SharePoint 2013 JSOM? All the field settings examples I've seen use spListItem.set_item(fieldName,fieldValue) which works great for simple fields like text or numbers, but it's failing for me on the plex URL field type. I've tried passing in my URL field name and a ma separated fieldValue = "descriptionText,url"

I've also tried SP.ListItem.parseAndSetFieldValue(fieldname,fieldValue), passing in the URL field name and the ma separated fieldValue = "descriptionText,url".

Am I missing something simple here?

Share Improve this question edited Mar 19, 2013 at 15:30 Rob 4,94712 gold badges52 silver badges56 bronze badges asked Mar 19, 2013 at 15:28 IntranogginIntranoggin 111 gold badge1 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Use the SP.FieldUrlValue object:

function updateListItem() {     
  var currCtx = new SP.ClientContext();          
  var web = currCtx.get_web();          
  var lists = web.get_lists();     
  var myList = lists.getByTitle("List1");     
  myItem = myList.getItemById(3);   
  var urlValue = new  SP.FieldUrlValue();
  urlValue.set_url("http://www.example.");
  urlValue.set_description("test link");
  myItem.set_item("TestURL", urlValue);     
  myItem.update();  

      currCtx.executeQueryAsync(onUpdateListSucceed, onFail);  }

here is an example on how to create a new SP.ListItem using javascript in SharePoint 2013 (Hyperlink or Picture):

 function createListItem() {  
   var clientContext = new SP.ClientContext(_spPageContextInfo.siteAbsoluteUrl);  
   var oList = clientContext.get_web().get_lists().getByTitle('TestList');  
   var itemCreateInfo = new SP.ListItemCreationInformation();  
   this.oListItem = oList.addItem(itemCreateInfo);

   var hyperLink = new SP.FieldUrlValue();  
   hyperLink.set_url("http://cnn.");  
   hyperLink.set_description("CNN");  
   oListItem.set_item('PetkaHyperLink', hyperLink);

 oListItem.update();  
   clientContext.load(oListItem);  
   clientContext.executeQueryAsync(  
     Function.createDelegate(this, this.onQuerySucceeded),   
     Function.createDelegate(this, this.onQueryFailed)  
   );  
 }

I got if from How to set any SP.Field Value with JSOM (Javascript) in Sharepoint 2013 to New SP.Listitem

发布评论

评论列表(0)

  1. 暂无评论