Is there A more efficient way to Write this Code

Hello,
I have designed t his procedure to give the proper response when a specific we request code is given. As you can see it is very long winded, What would be a more efficient way to make this work with less blocks? This procedure works, I would jsut like to learn how it can be made more efficient.

Regards,

You can try Dictionary block, add all the condions in single global variable as i did and use only one get value for the key… Remaining things blocks will do

image

In the place of 400 you can use get response code… simple

1 Like

Exactly like this, as @Still-learning said

1 Like

Yet Less Efficient but, My Try:
image
:slight_smile:

you can try this also… I believe the response code certainly will exists in this list, This also will give you reduced blocks but must be very cautious

image

In the place of number you could use get response code

There are multiple ways is there(once you started to involve much more with kodular, just kidding) but it is our choice to use for our convenient… Learning is always better than else…

Have you tried my approach with if key is in dictionary ?

1 Like

Thank You All for the different approaches. @dora_paz & @Still-learning I like this dictionary approach, its elegant and using the global variable method I can reuse them in other parts of the program and or projects. :+1: :+1: :grinning_face_with_smiling_eyes:

Regards,

1 Like

Follow-up,
Ok so taking what I learned yesterday, I designed these blocks. It functions, meaning it will send the http Request, however the response doesn’t show up. Its not immediately obvious to me what I’ve done wrong. I also couldn’t locate the “Do it results”

Please advise
Regards,

(post withdrawn)

1 Like

runtime error

Sorry, make changes like this…

image

misplaced the blocks…
your response code is the key of the dictionary… and global alert is the dictionary… pls refer the @dora_paz orry, make changes like this…

image

misplaced the blocks…
your response code is the key of the dictionary… and global alert is the dictionary… pls refer the @ post

This is how everything currently looks:

Everything works except the notify part.

image

Instead of procedure if you notifier, What you are getting? an proper response code as given in the dictionary keys?

OK some progress,
Running removing the procedure and running this give s a Not found when it should be 200 for OK. The http request is successful but the “global alerts” dictionary never gets checked.
notfound

Got your problem…

Me too Had the same issue early… Do one thing… In all the keys just add a letter like
A200, A404…

now in the procedure just use join block and it will become as Aresponse code…

I hope surely it will trigger…

The reason is, if the alert is number then notifier pop up an error or nothing… dont know whether it a bug or not…

I understand the first part Adding the A, I am just unclear where to add the Join block.

I meant like this,

image

1 Like

This definitely worked! I guess there is a Bug or it might be a feature.:wink:

Thank you for helping me troubleshoot! I know more than I did 2 yesterday :+1:.

image
[/quote]

1 Like

Yes, Dear Moderators and @Kodular please see to this point and take into your consideration…

While using web component, notifier does not work with response code (works well with alpha numeric code but doesnot with numeric)… We didnt see such issue earlier. For the last few days only we are experiencing,May be… I thought i was wrong, but after having experience with this user @Chaka_Hamilton , here by i am confirming and lodging this issue. Please review it…

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.