Taking Input from user in Service Portal Widget

june1994
Kilo Explorer

I am configuring a widget where i am giving the name of a user as input and there is a submit button,clicking on it it will show a message "Hello" with the Name of the user i given as input.

I have configured the widget but it is not showing any message after giving the input.

HTML:

find_real_file.png

Server Script:

find_real_file.png

Client Script:

find_real_file.png

Can anyone tell me where i am doing wrong wrong in the code??

9 REPLIES 9

ChrisBurks
Mega Sage

Hi Jhilik,



If the screenshot really captures the exact code you're using then on line 11 the .next method is missing the open and close parenthesis.


I forgot. You also might want to look at line 9. The script is passing in the "name" variable in the encoded query. Shouldn't "data.message" be passed in there instead as "data.message" has the data the user passed in.


Hi @Jamsta1912,

 

I see you marked this replay as helpful. Thanks for that, I'm glad I could at some level.

 

However, looking back at this now I probably skimmed this a little too quickly and actually missed a lot and gave a little bit of incorrect advise.

So just in case anyone comes across this post again or if the original poster never figured out the issue here is what is incorrect about the posted setup.

 

1) Line 9 server side script where the variable "name" is called should have been input.message since that is where the data being passed from the client side is being set ( the ng-model in the html markup)

2) Line 11 server side script the open/close parenthesis are missing where gr.next is called in the conditional

3) Line 5 in the client side script there is no argument being passed in the callback function for the promise which would make line 7 in the same client side script throw an error because the right side of the expression "data.name" would throw and error because "data" wouldn't be defined. And that should be changed to the match what the argument for the callback would be.

 

I think that should do it. I hope that helps for future viewers.

Ashley
Kilo Sage

Good Morning,

Did you ever get this resolved?

Kind Regards

Ashley

Oleg
Mega Sage

Even if we missing the code of HTML template of the widget one can see clear error in your server code.

The variable name isn't initialized. Thus its initial value in undefined. At initial loading of the page input variable will be undefined, the code inside of if (input) {...} block will be skipped and the line

data.name = "Hello"+name;

will be executed and data.name will be assigned to the string "Helloundefined" .

Then, if the user types some name and click the button you send new name probably as input.name or as input.message. On the other side you use the line

gr.addEncodedQuery("user_nameSTARTSWITH" + name);

 where name is always undefined. As the result query will return no records. The next error: you use

if (gr.next) {
     ...
}

instead of

if (gr.next()) {
    ...
}

It's short analyse of your existing code. I suppose you will be able to fix the code after that. Alternatively you can post more full code of your widget (at least HTML template) and I could help you to make it working as expected.