question

jansiranikrishnan-1796 avatar image
0 Votes"
jansiranikrishnan-1796 asked jansiranikrishnan-1796 commented

Need help on powershell coding regarding SCSM

Hi Team,

I am working on updating incident form in SCSM through a PowerShell script.

I have the value of a variable "$ResponseObject.Result" like below
![119345-image.png][1]

I would like to store the sys_id and SNOW ticket number in one of the field in the Incident form in SCSM. But the below code is not working. Any help is highly appreciated.
if ($Responseobject.result.status -eq "inserted")
{
$UpdateAlternateContact=@"
sys_id=$Responseobject.result.sys_id
SNOW Ticket Id=$Responseobject.result.number

"@
}

Set-SCSMObject -SMObject $IO -Property "AlternateContactMethod" -value $UpdateAlternateContact

Any help is highly appreciated.

Regards,
Jansi
[1]: /answers/storage/attachments/119345-image.png

windows-server-powershellmsc-service-manager
image.png (25.9 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @jansiranikrishnan-1796 ,

could you please post your PowerShell code as "Code sample Ctrl+k".
Copy & paste PowerShell code in normal Q&A text editor is deleting some characters.

If I got you right you want to add the values SNOW sys_id and SNOW ticket Id to the Alternate Contact property of an Incident?
For example the Alternate Contact should look like this 203e3eb12312731 INC0055836 ?


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

0 Votes 0 ·

Hi Andreas,

Below is the response for the web-service call from SNOW.

PS C:\Users\exjakri1_adm> $Responseobject.result

transform_map : Transform Staging Interface
table : u_interface_generic_transaction
display_name : sys_id
status : inserted
sys_id : c21f57971b6d7c101d777b75464bcb26
status_message : Successfully inserted incident number INC0055836
number : INC0055836
correlation_id : IR6177
record_sysid : 0e1f57971b6d7c101d777b75464bcb40


I would like to store as below in AlternateContactMethod field in Incident Form.

Sys_id: c21f57971b6d7c101d777b75464bcb26
SNOW ticket number: INC0055836
Correlation_id: IR6177


Hope this information is sufficient.

Regards,
Jansi

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered jansiranikrishnan-1796 commented

Hi @jansiranikrishnan-1796 ,

here we go:

 Import-Module SMlets
 $smdefaultserver = "SCSM1"
 # Define properties
 $irID = "IR2103"
 $SysID = "c21f57971b6d7c101d777b75464bcb26"
 $SNOWticketID = "INC0055836"
 $status = "inserted"
 ######
 $irClass = Get-SCSMclass -name System.Workitem.Incident$
 # Get SCSM objects
 $irObj = Get-SCSMObject -Class $irClass -Filter "ID -eq $irID"
 # Update IR Alternate Contact Method
 if (($status -eq "inserted") -and ($irObj)) {
     $UpdateAlternateContact = "Sysid: $SysID | SNOW ticket number: $SNOWticketID | Correlation_id: $irID"
     Set-SCSMObject -SMObject $irObj -Property "ContactMethod" -value $UpdateAlternateContact
 }


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Andreas,

Is it possible to update the field value in 3 lines like below rather in single line with "|" delimited.

Sys_id: c21f57971b6d7c101d777b75464bcb26
SNOW ticket number: INC0055836
Correlation_id: IR6177

Regards,
Jansi

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered jansiranikrishnan-1796 commented

Hi @jansiranikrishnan-1796 ,

the "Alternate Contact Method" text field in the Incident form is a single line. Using values 3 different lines might be not optimal.

But anyway. If you like the values in 3 lines please try this:

  Import-Module SMlets
  $smdefaultserver = "SCSM1"
  # Define properties
  $irID = "IR2103"
  $SysID = "c21f57971b6d7c101d777b75464bcb26"
  $SNOWticketID = "INC0055836"
  $status = "inserted"
  ######
  $irClass = Get-SCSMclass -name System.Workitem.Incident$
  # Get SCSM objects
  $irObj = Get-SCSMObject -Class $irClass -Filter "ID -eq $irID"
  # Update IR Alternate Contact Method
  if (($status -eq "inserted") -and ($irObj)) {
      $UpdateAlternateContact = "Sysid: $SysID `r`n SNOW ticket number: $SNOWticketID `r`n Correlation_id: $irID"
      Set-SCSMObject -SMObject $irObj -Property "ContactMethod" -value $UpdateAlternateContact
  }


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Andreas,

You are very much correct. "Alternate Contact Method" is a single line field in Incident form. So i followed the single line with pipe delimited text rather than 3 separated lines as it looks clumsy after updating.

My last question to this thread is How to retrieve the value of the Sys_id from the "Alternate Contact Method" field. I may have to use this as reference while sending any incident information to SNOW.

SNOW SYS ID: c21f57971b6d7c101d777b75464bcb26 | SNOW INCIDENT NUMBER: INC0055836 | SNOW CORRELATION ID: IR6177

Regards,
Jansi


[1]: /answers/storage/attachments/120086-image.png

0 Votes 0 ·
image.png (5.3 KiB)
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered jansiranikrishnan-1796 commented

Hi @jansiranikrishnan-1796 ,

here we go:

 # Alternate Contact Method property
 $a = "SNOW SYS ID: c21f57971b6d7c101d777b75464bcb26 | SNOW INCIDENT NUMBER: INC0055836 | SNOW CORRELATION ID: IR6177"
 # Get SysID
 $sysID = ($a.Split("|")[0].Split(":").Trim())[1]
 $SysID
 # Get SNOW Ticket ID
 $SNOWticketID = ($a.Split("|")[1].Split(":").Trim())[1]
 $SNOWticketID
 # Get SCSM IR ID
 $irID = ($a.Split("|")[2].Split(":").Trim())[1]
 $irID


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you so much Andreas for sharing the information.

Regards,
Jansi

0 Votes 0 ·