Guest User

Untitled

a guest
Mar 19th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. private async addCol(fieldName, guid): Promise<any> {
  2. const digestCache: IDigestCache = this.context.serviceScope.consume(DigestCache.serviceKey);
  3. digestCache.fetchDigest(this.context.pageContext.web.serverRelativeUrl).then((digest: string): void => {
  4. let obj = {};
  5.  
  6. if (fieldName == "Full Address") {
  7. obj = "{ '__metadata': { 'type': 'SP.FieldText' }, 'FieldTypeKind': 2,'Title': 'Full Address'}";
  8. }
  9. if (fieldName == "Description") {
  10. obj = "{ '__metadata': { 'type': 'SP.FieldText' }, 'FieldTypeKind': 2,'Title': 'Description' }";
  11. }
  12. if (fieldName == "Location") {
  13. obj = "{ '__metadata': { 'type': 'SP.Field' }, 'FieldTypeKind': 31, 'Title': 'Location' }"
  14. }
  15. console.log("Post data: ");
  16. console.log(obj);
  17.  
  18. $.post({
  19. url: this.context.pageContext.site.serverRelativeUrl + "/_api/web/lists(guid'" + guid + "')/fields",
  20. type: "POST",
  21. data: obj,
  22. headers: {
  23. "accept": "application/json;odata=verbose",
  24. "content-type": "application/json;odata=verbose",
  25. "X-RequestDigest": digest,
  26. },
  27. success: function (data) {
  28. //console.log("done");
  29. //console.log(data)
  30. console.log("added: " + fieldName);
  31. },
  32. error: function (response) {
  33. console.log(response.responseText);
  34. }
  35. });
  36. });
  37. }
  38.  
  39. {"error":{"code":"-2147023746, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The specified program requires a newer version of Windows. (Exception from HRESULT: 0x8007047E)"}}}
Add Comment
Please, Sign In to add comment