Home Analyst Portal
Options

Is it possible to create System.WorkItem.TroubleTicket. AnalystCommentLog via the Cireson API?

John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
edited February 2019 in Analyst Portal
Is it possible to create System.WorkItem.TroubleTicket.AnalystCommentLog via the Cireson API?
Specifically trying to avoid SMLets unless I have to! :)

Best Answers

Answers

  • Options
    John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
    Thanks @Geoff_Ross ! Yeah the script I'm using leverages a service account but will be checking for permissions as part of the function. Use case is same as here :: https://community.cireson.com/discussion/4648/logicapps-custom-connector-openapi-swagger

  • Options
    John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
    Found it @Geoff_Ross ! AppliesToTroubleTicket! Was working on a test incident with no comments, hence nothing to see! Added one and there it was.
  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Exellent
  • Options
    John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
    @Geoff_Ross , any chance you can put me out of my misery on why this projection won't commit?
    Have redacted the bits that reference assigned to, requested user, create user.

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference   at CallSite.Target(Closure , CallSite , Object , String )   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)   at Cireson.ServiceManager.Services.Implementations.ProjectionPersistenceService.<CommitAsync>d__7.MoveNext()--- End of stack trace from previous location where exception was thrown ---

    etc. etc.

  • Options
    John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
    @Geoff_Ross , any chance you can put me out of my misery on why this projection won't commit?
    Have redacted the bits that reference assigned to, requested user, create user.


    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference   at CallSite.Target(Closure , CallSite , Object , String )   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)   at Cireson.ServiceManager.Services.Implementations.ProjectionPersistenceService.<CommitAsync>d__7.MoveNext()--- End of stack trace from previous location where exception was thrown ---

    etc. etc.


  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.
    @John_Long

    I looks good to me but very hard to tell. My advice would be to work in PowerShell, see if the projection can be committed without any changes. If not, start chopping bits out the JSON until it does. If it does commit without changes, what are you changing?

    Geoff
  • Options
    John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
    @Geoff_Ross forgot to wrap current and original in a formJson key. Doh!
  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Ah, thats the one!
  • Options
    John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
    @Geoff_Ross , still having issues sadly. Portal API reports success but no comment in console, DB or web portal. If you can share your example for an "System.WorkItem.TroubleTicket.AnalystCommentLog" that would be awesome.

    At present, it feels a lot like stumbling in the dark. No validation errors or permissions issues in the logs.

  • Options
    John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
    @Geoff_Ross , bump! Would appreciate a PoSH sample if you have one! Commit of projection reports success but no comment visible in portal!
  • Options
    John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
    Thanks @Marc-Andre_Lafleur ! In my current use case I'm using Python. I did expect that a PoSH example would be easier. Will try the structure you use above.

    My code to construct the comment:

    
            # Create comment object
            base_id = str(uuid.uuid4())
            display_name = str(uuid.uuid4())
            current_datetime = (str(datetime.datetime.now().isoformat()))
            comment = {
                "BaseId" : base_id,
                "ClassName" : "System.WorkItem.TroubleTicket.AnalystCommentLog",
                "ClassTypeId" : "f14b70f4-878c-c0e1-b5c1-06ca22d05d40",
                "Comment" :  comment,
                "DisplayName" : display_name,
                "EnteredBy" : str(user.get('DisplayName','API-User')),
                "EnteredDate" : current_datetime,
                "FullClassName" : "Trouble Ticket Analyst Comments",
                "FullName" : f"System.WorkItem.TroubleTicket.AnalystCommentLog:{display_name}",
                "Id" : display_name,
                "IsPrivate" : isPrivate,
                "LastModified" : current_datetime,
                "LastModifiedBy" : str(user.get("BaseId","7431e155-3d9e-4724-895e-c03ba951a352")),
                "Path" : None,
                "TimeAdded" : current_datetime,
                "Title" : "Analyst Comment"
            }
            # Deep copy original work item formJSON
            #logging.info(wi.json)
            original = copy.deepcopy(wi.json)
            # Reference original work item
            current = copy.deepcopy(wi.json)
            
            # Append comment object to array
            current.get('AppliesToTroubleTicket').append(comment)
            
            formJson = {
                "formJson" : {
                    "original" : original,
                    "current" : current
                }
            }
            # Update Current Projection LastModified
            formJson['formJson']['current']['LastModified'] = current_datetime
            
            logging.info(f"AddComment :: {json.dumps(formJson)}")
            try:
                response = Projection.CommitProjection(formJson=formJson, concurrency_check=True)
                return response
            except:
                logging.error("Unable to submit System.WorkItem.TroubleTicket.AnalystCommentLog")
                return False


  • Options
    John_LongJohn_Long Customer Advanced IT Monkey ✭✭✭
    @Marc-Andre_Lafleur thanks! your code is a valid structure! It's not a private comment, but it saves! I'll take it! Would love to know why my structure didn't fly! <3
Sign In or Register to comment.