logo

NJP

ServiceNow Jira Spoke: Project to Project Pt 4 (Users Fix)

Import · Aug 24, 2023 · video

foreign [Music] it's Justin thank you for watching and welcome to my house that's Justin's house in this video I have part four yes part four I was only gonna do three parts on this project to project sync between servicenow and jira but when I edited part three I realized um I made a mistake um it's not too big of a mistake it's going to be really obvious if you didn't catch it already I've got the flow up here behind me this is the simple flow I have to synchronize jira user information with servicenow user information by putting the user information in a like a one-to-one table right so that's all that's happening here and I can't believe I missed this but basically I have it running every Wednesday for me you can run this every day you can run this several times a day if you wanted but I only codified or thought about the create kind of scenario and not like oh the record might already be there and we don't need to create it again I don't know what I I was thinking I was just trying to get to a fix to get rid of what I was doing so let's fix this real quick let's go take a look at that table there we go I got my table here so I'm going to show list I don't think it says run since I last did it yeah so there's just me so if I'm right if I run this again it's going to create another row of just me and that's not what we want we don't want this running and creating several rows because that's just a waste of time for the system and it's a waste of space in the database let's go just refresh that see if it does like I think it's going to do yes it created me twice we don't want it to do that everybody so let's go ahead and delete that extra one and we'll fix this flow we're going to do the flow a similar way we do the project right remember the project flow the sync projects flow there was kind of a hey is it already there if it is update it and if it's not already there we're using a try and catch to do that if it's not already there then create it so we're going to do something similar with the users that we did with the project so you can see it there if it's already created update it if not go ahead and create it we need the same the same exact flow for the users so let's fix it we are going to for each user in the lookup stream before we look up the user record we're actually going to look up and see if they're inside of our table already so let's go ahead and do a lookup that took a ridiculously not a long time amount of time so I'm going to go ahead and shorten that for you but we're going to look up and see if they are in our gr users table remember my trick here hit done open it again and see if that table is ready just give it a minute it's basically going through the entire system and populating this drop down with all the tables so that could take a second uh jira users there we go and we'll match on the email address of course so we look at the um in the jira user table there should be a reference to the user gosh there it is user and then we should have email address so we'll see if they already exist in our table and we'll match that to the for Loop um look or the lookup user stream which is Step number one you will okay I can't do it let me go back up here for each item oh it is one okay so that's right for some reason I was thinking that wasn't a for Loop because it didn't say for each object here so okay user object look up users in stream user and then we want email address okay so we're going to look up and see if they're there if they are we don't need to do this this is going to be what we do if we fail right so let's go ahead and move these down to if an error occurs um okay let's move let's move this one down first let's see if that actually works I don't know if this is I'm probably gonna have to redo some stuff but that's okay so we'll move four and five down to right there okay so if an error occurs it's going to look up the email address and then create the jury user record if it does find it then we just need to update the record so let's go to action and then update record and what we'll do is say the record we want to update is the one we just looked up so let's just go to that one look up record get your user record and the only thing to update is the um the account ID right so let's go ahead and do jira account ID and set it so theory in theory I guess that account ID could change for some reason the email gets associated with a different account and we need to update it in the table and then if it doesn't if it's not able to look it up then it's going to go ahead and look up the user record where the email matches and create the to your user record so we want it to do that right so let's go ahead and save this wallet saving I'm actually going to delete me entirely because we need to make sure that it still creates we need to test both scenarios that it creates and that it updates so let's go ahead and delete that and go back here to flow designer it is saved let's go ahead and test now we're expecting in this test it should create that it shouldn't try to update anything because it doesn't exist it'll fail in this tri-step and instead it should go ahead and create it so let's go back to the table and let's go ahead and refresh the list and it didn't get make it into my uh my creation stuff so for some reason that try actually worked I don't know why well let's go oh dude I have to do it again we'll click on the history see if we get an error message yeah we'll get an error message all right so the lookup error cot there and then when it did the after step two the look up there oh this is the same error we were getting before where um it was causing an issue where it didn't didn't find anything so we still needed another try catch within our tri-cuts um though I should have known that so okay we can close this project one here cancel out of there okay so this I moved this out of the try because um it doesn't need to be at this part but it still needs its own try catch in case it fails so let's go ahead and add flow logic we'll do a try there and uh we'll move that back in to that step so it's going to try that and then if that works it's going to go ahead and create it and that way if it doesn't work it won't stop the entire flow like you just saw it did because on the first email it couldn't find it to air it out and stops the flow we don't want that behavior we want to catch the error and keep on moving is what we want so now that we've fixed that let's just refresh our table make sure even though I've failed that there's nothing there we're good and we'll go ahead and test run test and we'll click on the test results and everything worked as it should so we should have one account in here and that's me with my account ID um nope the user didn't work so it is not working even like it did before all right time to troubleshoot I got a lot of good feedback in other videos If you guys like the troubleshooting so I'm going to keep the troubleshooting in all right let's take a look at this again so for every user in the Stream it's going to try to look up the record if it and if it finds it it's going to update it and then if that lookup fails it's going to try to look up a user record oh I know what I bet when no email is not empty email is and then look up the email address okay so that's all good and then create the zero user record select oh look at that all right so when I move that it doesn't have the reference to the record anymore so let's go ahead and fix that that was step number seven lookup record and it'll be so I did actually I think if I remember the video right I did the user record and then I did the sys ID it's how I was doing that and then the jira account ID is going to be step number one the account ID which is correct that's all we want there it looks a little funny on the previous screen but okay done save and let's delete this again see that's funny the 557058 that shouldn't be there but uh let's delete that delete and let's just check it one more time so it an error occurs because they're not in the table and then so now we're going to try to look up the user record where the email is not empty and the email is the email address that's in the lookup user stream okay so that's what worked before and then that only returns one record and then it creates a zero user record by us passing the user information from the previous step and the account ID from the lookup user stream so that's done and that's ready to test since it's already saved we'll run the test and now we should have an account ID in my user account when we go look at the table once this finishes here so I think it was just that one missing data pill on there Let's cross our fingers and our toes and yes it worked so I've got my jira account ID and my user information so now we want to test the update step so let's go ahead and open this record I guess I could have just clicked on the Blue Link and to test the update step we're just going to put some nonsense in here we'll like tests for YouTube right so now this doesn't match what it should be which is that account ID and it's okay because it's going to be looking up the username when it does this update set update Step at the top right so it's matching on email not the account ID so let's test it again and what we should see is this gets fixed it goes from test for YouTube back to the regular sys ID so right now it has tests for YouTube in there we'll go ahead and run the test let that go test is finished we should not see an extra user record or two like we did at the beginning we should just see this get fixed we'll refresh the list and there it goes now it's fixed all right so that's what the flow should have looked like originally but for some reason Justin forgot about the fact that that user would be in the table already so that's the basic flow look them up if they're there update the record if they're not there catch that error go ahead and create it and in our case when we're creating we need to do another try and catch that error just in case the the user doesn't exist in the user table so I hope you found this fourth and last video helpful if you did please like Please Subscribe or share it with somebody who you think might be interested in integrating projects in service now to projects in jira or synchronizing users in servicenow with users in jira and until next time don't forget to all always be learning [Music] foreign

View original source

https://www.youtube.com/watch?v=oCF0Zo4tgxM