0

I have an on execute method that has variable "item". I need to pass that variable to my other method "IsStatusChangeValid"

Below is what I currently have, but so far its not working. I looked at some related questions on stack overflow such as Accessing Variables From Another Method and looked at some parameter passing tutorials/examples online such as Parameter Passing in C# but I have been unable to apply the information properly.

protected override CommandResult OnExecute()
{
    var item = ItemViews.ItemGet(itemId);

    if (IsStatusChangeValid())
    { 
        ...
    }
    else
    { 
        ... 
    }
}

public bool IsStatusChangeValid(item)
{
    // ONLY IF SET EXISTS
    if (item.ItemSets.Count > 0)
    {
        // CHECK IF ITEM STATUS IS CHANGED TO "CLOSED-VOIDED"
        if (newDescription.Equals("Closed-Voided"))
        {
            // IF THERE ARE NON-VOIDED SETS, DO NOT ALLOW THE STATUS CHANGE
            if (item.ItemSets.Any(p => p.SetStatusID != SetStatusIDConstants.Voided))
            {
                return false;
            }
        }
    }
    return true;
}
8
  • How are you trying to call the second method? from with inside the OnExecute method? What did you try that didn't work (and why didn't it work)? Commented Apr 23, 2015 at 13:31
  • Sayse: I have an if statement in OnExecute that does if (IsStatusChangeValid) {do work} else {stop and post warning} I've tried IsStatusChangeValid(item) and IsStatusChangeValid(ItemViews item) and IsStatusChangeValid(Item item) The first one throws an error under item. The second two throw errors from within the IsStatusChangeValid method. Commented Apr 23, 2015 at 13:34
  • And how have you tried to use it? Your second link has a fairly decent example under Value parameters Commented Apr 23, 2015 at 13:36
  • sorry. just updated that previous comment with what I have tried. Commented Apr 23, 2015 at 13:38
  • IsStatusChangeValid(item) is correct, what error did you get Commented Apr 23, 2015 at 13:38

1 Answer 1

5

There are two mistakes you made in your code

  1. The declaration of the method

You must define what type a parameter is

public bool IsStatusChangeValid(Item item)
  1. You must pass in an item into the call of the method
if(IsStatusChangeValid(item))
Sign up to request clarification or add additional context in comments.

2 Comments

and no more errors. Thank you for your assistance. You've been very helpful.
@AtlasBowler - No worries, I've just seen that MSDN has a page on passing parameters that you may find more useful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.