This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
How to get a value from a specific JavaScript Object?
#1
I have a Object with the following structure:

{
  id: 9215,
  rev: 8,
  fields: {
    "System.Id": 9215,
    "System.AreaId": 277,
    "System.AreaPath": "GisAtWeb",
    "System.TeamProject": "GisAtWeb",
    "System.NodeName": "GisAtWeb",
    "System.AreaLevel1": "GisAtWeb",
    "System.Rev": 8,
    "System.AuthorizedDate": "2021-01-28T13:15:15.623Z",
    "System.RevisedDate": "9999-01-01T00:00:00Z",
    "System.IterationId": 269,
    "System.IterationPath": "GisAtWeb",
    "System.IterationLevel1": "GisAtWeb",
    "System.WorkItemType": "Task",
    "System.State": "Done",
    "System.Reason": "Work finished",
    "System.CreatedDate": "2021-01-27T16:20:49.98Z",
    "System.CreatedBy": {
      displayName: "Schulze, Markus",
      url: "****",
      _links: [Object],
      id: "b5d776ba-c31e-6957-8ec4-5623fe2b1118",
      uniqueName: "Markus.Schulze@vwfsdev.com",
      imageUrl: "****",
      descriptor: "aad.YjVkNzc2YmEtYzMxZS03OTU3LThlYzQtNTYyM2ZlMmIxMTE4"
    },
    "System.ChangedDate": "2021-01-28T13:15:15.623Z",
    "System.ChangedBy": {
      displayName: "Dominic Taubald",
      url: "****",
      _links: [Object],
      id: "8270861f-3fe2-6e7d-a347-ec9f1ecd20f2",
      uniqueName: "Dominic.Taubald@vwfsdev.com",
      imageUrl: "****",
      descriptor: "aad.ODI3MDg2MWYtM2ZlMi03ZTdkLWEzNDctZWM5ZjFlY2QyMGYy"
    },
    "System.AuthorizedAs": {
      displayName: "Dominic Taubald",
      url:
        "https://spsprodweu4.vssps.visualstudio.com/A511b7ce7-5e78-4cdc-b847-d020b420fde2/_apis/Identities/8270861f-3fe2-6e7d-a347-ec9f1ecd20f2",
      _links: [Object],
      id: "8270861f-3fe2-6e7d-a347-ec9f1ecd20f2",
      uniqueName: "Dominic.Taubald@vwfsdev.com",
      imageUrl: "****",
      descriptor: "aad.ODI3MDg2MWYtM2ZlMi03ZTdkLWEzNDctZWM5ZjFlY2QyMGYy"
    },
    "System.PersonId": 81022228,
    "System.Watermark": 78852,
    "System.CommentCount": 0,
    "System.Title":
      "[20210127] Deployment Task - Changelog aktualisieren / prüfen gegen Deployment-Script",
    "Microsoft.VSTS.Common.StateChangeDate": "2021-01-28T13:15:15.623Z",
    "Microsoft.VSTS.Common.ClosedDate": "2021-01-28T13:15:15.623Z",
    "Microsoft.VSTS.Common.ClosedBy": {
      displayName: "Dominic Taubald",
      url: "****",
      _links: [Object],
      id: "8270861f-3fe2-6e7d-a347-ec9f1ecd20f2",
      uniqueName: "Dominic.Taubald@vwfsdev.com",
      imageUrl: "****",
      descriptor: "aad.ODI3MDg2MWYtM2ZlMi03ZTdkLWEzNDctZWM5ZjFlY2QyMGYy"
    },
    "Microsoft.VSTS.Common.Priority": 2,
    "System.Description":
      '<div><b><u>Changelog:</u></b></div><div><br></div><div>Folgende Konfigurationen müssen im Deployment-Script berücksichtigt werden:</div><div><br></div><div><ul><li>Konfiguration der Route über IDP ohne BlueCoat Proxy (ICAP Virenscanner Komponente) ist im APIM Korrekt hinterlegt. (<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;">Statt <i>fsb-gateway.vwfs.com</i>\n' +
      'wird <i>gateway-cert.vwfs.com </i>mit SSL verwendet) Siehe Screenshot</span></li><li><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;">Anpassung Deployment-Script, wenn das Zertifikat manuell im Portal geändert wurde: Anpassung Fingerprint (Zertifkats-Id) im Deployment-Script</span></li><li><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;"><br></span></li></ul></div><div><br><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;"></span></div><div><img src="https://dev.azure.com/vwfs/55bf3504-405f-46ad-a342-fb8edcf4913f/_apis/wit/attachments/21e69dea-3b77-4baa-bc80-e4f4b6bbd370?fileName=sc.jpg" alt=sc.jpg><br></div>'
  },
  _links: {
    self: {
      href: "****"
    },
    workItemUpdates: {
      href: "****"
    },
    workItemRevisions: {
      href: "****"
    },
    workItemComments: {
      href: "****"
    },
    html: {
      href: "****"
    },
    workItemType: {
      href: "****"
    },
    fields: {
      href: "****"
    }
  },
  url: "link"
};




I want to get specific values from the object with:

uid: String(WorkItem.id),
url: WorkItem.url,
type: String(WorkItem.fields.System.WorkItemType),
name: WorkItem.fields.System.Title,

For id and url everything works fine but for the fields.System values I get "Error processing input: Cannot read properties of undefined" How can I get the values fro the fields.System properties? I tried a different synthax but everything failed.
Zitieren
#2
Unfortunately, I don't know your attempts, and whether you still use Jsons.parse or strinfify.
With the code I see now, you could do it like this.

var array = {
  id: 9215,
  rev: 8,
  fields: {
    "System.Id": 9215,
    "System.AreaId": 277,
    "System.AreaPath": "GisAtWeb",
    "System.TeamProject": "GisAtWeb",
    "System.NodeName": "GisAtWeb",
    "System.AreaLevel1": "GisAtWeb",
    "System.Rev": 8,
    "System.AuthorizedDate": "2021-01-28T13:15:15.623Z",
    "System.RevisedDate": "9999-01-01T00:00:00Z",
    "System.IterationId": 269,
    "System.IterationPath": "GisAtWeb",
    "System.IterationLevel1": "GisAtWeb",
    "System.WorkItemType": "Task",
    "System.State": "Done",
    "System.Reason": "Work finished",
    "System.CreatedDate": "2021-01-27T16:20:49.98Z",
    "System.CreatedBy": {
      displayName: "Schulze, Markus",
      url: "****",
      _links: [Object],
      id: "b5d776ba-c31e-6957-8ec4-5623fe2b1118",
      uniqueName: "Markus.Schulze@vwfsdev.com",
      imageUrl: "****",
      descriptor: "aad.YjVkNzc2YmEtYzMxZS03OTU3LThlYzQtNTYyM2ZlMmIxMTE4"
    },
    "System.ChangedDate": "2021-01-28T13:15:15.623Z",
    "System.ChangedBy": {
      displayName: "Dominic Taubald",
      url: "****",
      _links: [Object],
      id: "8270861f-3fe2-6e7d-a347-ec9f1ecd20f2",
      uniqueName: "Dominic.Taubald@vwfsdev.com",
      imageUrl: "****",
      descriptor: "aad.ODI3MDg2MWYtM2ZlMi03ZTdkLWEzNDctZWM5ZjFlY2QyMGYy"
    },
    "System.AuthorizedAs": {
      displayName: "Dominic Taubald",
      url:
        "https://spsprodweu4.vssps.visualstudio.com/A511b7ce7-5e78-4cdc-b847-d020b420fde2/_apis/Identities/8270861f-3fe2-6e7d-a347-ec9f1ecd20f2",
      _links: [Object],
      id: "8270861f-3fe2-6e7d-a347-ec9f1ecd20f2",
      uniqueName: "Dominic.Taubald@vwfsdev.com",
      imageUrl: "****",
      descriptor: "aad.ODI3MDg2MWYtM2ZlMi03ZTdkLWEzNDctZWM5ZjFlY2QyMGYy"
    },
    "System.PersonId": 81022228,
    "System.Watermark": 78852,
    "System.CommentCount": 0,
    "System.Title":
      "[20210127] Deployment Task - Changelog aktualisieren / prüfen gegen Deployment-Script",
    "Microsoft.VSTS.Common.StateChangeDate": "2021-01-28T13:15:15.623Z",
    "Microsoft.VSTS.Common.ClosedDate": "2021-01-28T13:15:15.623Z",
    "Microsoft.VSTS.Common.ClosedBy": {
      displayName: "Dominic Taubald",
      url: "****",
      _links: [Object],
      id: "8270861f-3fe2-6e7d-a347-ec9f1ecd20f2",
      uniqueName: "Dominic.Taubald@vwfsdev.com",
      imageUrl: "****",
      descriptor: "aad.ODI3MDg2MWYtM2ZlMi03ZTdkLWEzNDctZWM5ZjFlY2QyMGYy"
    },
    "Microsoft.VSTS.Common.Priority": 2,
    "System.Description":
      '<div><b><u>Changelog:</u></b></div><div><br></div><div>Folgende Konfigurationen müssen im Deployment-Script berücksichtigt werden:</div><div><br></div><div><ul><li>Konfiguration der Route über IDP ohne BlueCoat Proxy (ICAP Virenscanner Komponente) ist im APIM Korrekt hinterlegt. (<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;">Statt <i>fsb-gateway.vwfs.com</i>\n' +
      'wird <i>gateway-cert.vwfs.com </i>mit SSL verwendet) Siehe Screenshot</span></li><li><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;">Anpassung Deployment-Script, wenn das Zertifikat manuell im Portal geändert wurde: Anpassung Fingerprint (Zertifkats-Id) im Deployment-Script</span></li><li><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;"><br></span></li></ul></div><div><br><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;"></span></div><div><img src="https://dev.azure.com/vwfs/55bf3504-405f-46ad-a342-fb8edcf4913f/_apis/wit/attachments/21e69dea-3b77-4baa-bc80-e4f4b6bbd370?fileName=sc.jpg" alt=sc.jpg><br></div>'
  },
  _links: {
    self: {
      href: "****"
    },
    workItemUpdates: {
      href: "****"
    },
    workItemRevisions: {
      href: "****"
    },
    workItemComments: {
      href: "****"
    },
    html: {
      href: "****"
    },
    workItemType: {
      href: "****"
    },
    fields: {
      href: "****"
    }
  },
  url: "link"
};

console.log(array.id);


console.log(array.fields["System.Id"]);
console.log(array.fields["System.AreaId"]);
console.log(array.fields["System.AreaPath"]);
console.log(array.fields["System.TeamProject"]);
console.log(array.fields["System.NodeName"]);
console.log(array.fields["System.AreaLevel1"]);
console.log(array.fields["System.Rev"]);
console.log(array.fields["System.AuthorizedDate"]);
console.log(array.fields["System.RevisedDate"]);
console.log(array.fields["System.IterationId"]);
console.log(array.fields["System.IterationPath"]);
console.log(array.fields["System.IterationLevel1"]);
console.log(array.fields["System.WorkItemType"]);
console.log(array.fields["System.State"]);
console.log(array.fields["System.Reason"]);
console.log(array.fields["System.CreatedDate"]);


console.log(array.fields["System.CreatedBy"]["displayName"]);
console.log(array.fields["System.CreatedBy"]["url"]);
console.log(array.fields["System.CreatedBy"]["_links"]);
console.log(array.fields["System.CreatedBy"]["id"]);
console.log(array.fields["System.CreatedBy"]["uniqueName"]);
console.log(array.fields["System.CreatedBy"]["imageUrl"]);
console.log(array.fields["System.CreatedBy"]["descriptor"]);
Hier sind alle meine Lösungen aus allen Foren. Ich helfe auch in Facebook-chat
Als Lösung markieren Zitieren
#3
Thank you very much @admin . You solved my problem. But now I have another problem. In some cases there is a key
"System.Parent"
and in some cases it is not there at all. I get an exception if it is not there at all. How can I check if the object has this key with a value?
Als Lösung markieren Zitieren
#4
My English is not that good.
You can have a look here.
I think this should help you
https://stackoverflow.com/questions/1098...ipt-object
Hier sind alle meine Lösungen aus allen Foren. Ich helfe auch in Facebook-chat
Als Lösung markieren Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste