Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:59:28+00:00 2026-06-15T06:59:28+00:00

The code looks fine to me which is why I’m confused with the G_SResult

  • 0

The code looks fine to me which is why I’m confused with the G_SResult variable losing scope. It’s declared globally above the ready function but that isn’t visible in the screenshot. In the screenshot you will see 4 highlighted alert expressions. The one with the red dot is where it returns undefined. The other alerts return the right value.

Screenshot of the code.—-> https://i.stack.imgur.com/LQPeB.png

function Savedat(){
          var Surveyz=new Survey();
          Surveyz.Name=j$('#survey_name').val();
          var SResult;
          var QuestionOrder=1;
          var id;
          //alert(G_SResult+'----first');
          //alert(typeof G_SResult === 'undefined');
          Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.SV_CreateSurvey.insertSurvey}'
              ,Surveyz
              ,function(Survey_result, event){
                console.log(Survey_result);
                SResult=Survey_result;

             j$('[name="p_Q"]').each(function(){
                 elId=this.id;
                 var elNum=elId.substring(1);

                 QType=j$('input[name=ctrlSel'+elNum+']:checked').val();
                 Quest=new Question();
                 Quest.Question__c=j$(this).val();
                 Quest.Question_Input_Type__c=QType;

                 SResult=Survey_result;
                 G_SResult=SResult;
                  alert(G_SResult+'---1'); 
                 Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.SV_CreateSurvey.insertQuestion}'
                      ,Quest
                      ,function(Question_result, event){
                        console.log(Question_result);

                        var SQLink=new SurveyQL();
                        SQLink.SG_Survey__c=SResult;
                        SQLink.Survey_Question__c=Question_result;
                        SQLink.QOrder__c=(QuestionOrder);
                        Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.SV_CreateSurvey.insertSurveyLink}'
                              ,SQLink
                              ,function(SurveyLink_result, event){
                                console.log(SurveyLink_result);
                         });

                        j$('[name="A'+elNum+'"]').each(function(){

                             SA=new SurveyAnswer();
                             SA.Answer__c=j$(this).val();
                             SA.Survey_Question__c=Question_result;

                             Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.SV_CreateSurvey.insertAnswer}'
                              ,SA
                              ,function(Answer_result, event){
                                console.log(Answer_result);

                             });
                        });
                     QuestionOrder++;

                 });
                 alert(G_SResult+'----2'); 
             });

            alert(G_SResult+'----3'); 
         });


    setTimeout(function(){Work();}, 1000);


}

In case anyone ever comes across this for whatever reason, the solution was this…
(Both code blocks have been edited as a working example)

function Work()
{
    //Semaphore like
    if (typeof G_SResult === 'undefined')//(G_SResult == undefined)
    {
      //run stuff here
        setTimeout(function(){Work();}, 1000);
    }
    else
    {
      alert(G_SResult+'----5');



      //G_SResult = null;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:59:29+00:00Added an answer on June 15, 2026 at 6:59 am

    Looks like Visualforce.remoting.Manager method is Asynchronous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code (which works fine) that looks something like this: int integer
I have code that looks like the following, which works fine for displaying the
My code looks fine but it is not working as it should because update
So what my code looks like.. Now the problem is that Everything is fine
My Android app uses Button widgets with default style, which looks fine except on
I have a code that looks like code below in a PC which runs
I've got a piece of code that works fine. It basically loops through each
Code looks like that #include <cstdlib> #include <iostream> using namespace std; #define n 3;
My code looks like <html> <head> <title>My HTML application</title> <HTA:APPLICATION id=frames border=thin caption=yes icon=http://www.google.com/favicon.ico
My code looks somehow like this: //INCLUDES FILE *file; void handlesocket(int socket); int main(int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.