[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Help with IF statement in Querysave

Experts,

I need to edit code in the querysave which looks at specific fields and based on their values, sets a reader field to a role.  This is working fine.  I now have included a new field to check another set of values and need to also set the reader field to another role.  So, both checks need to work.  I tried to revise the code -- and its not working -- no errors -- it just doesn't set the reader field when I try to check for both validations.  If I do each separately -- it works fine.

please help:

Code is included.

The first portion is the original code., the 2nd is my attempt checking for:
if the SubTopic field contains "Rate files" and the RateDistribution field is "Stage 1" then the reader field should be PricingStage1 -- all of the rest of the code (as in the original) is fine.

I may also need to include a check for if RateDistribution field is "Stage 2" then the reader field should be PricingStage2 (not sure on this -- but can it be worked into the code??)

Thanks!
'Set Readers Name
	If doc.DocTopic(0) = "Project Management" And doc.SubTopic(0) = "Financials" Then
		If doc.HasItem("DocReaders") Then
			Call doc.ReplaceItemValue("DocReaders",  "[FinanceViewer]")
			Set item = doc.GetFirstItem("DocReaders")
			item.IsReaders = True
			item.IsSummary = True
		Else
			Set item = New NotesItem( doc, "DocReaders" , "[FinanceViewer]" , READERS )   
			Item.IsSummary = True
		End If 
	Else
		If doc.HasItem("DocReaders") Then
			Call doc.ReplaceItemValue("DocReaders",  "[All]")
			Set item = doc.GetFirstItem("DocReaders")
			item.IsReaders = True
			item.IsSummary = True
		Else
			Set item = New NotesItem( doc, "DocReaders" , "[All]" , READERS )   
			Item.IsSummary = True
		End If
	End If	

===============================

here is my attempt at trying to check for both instances:

     'Set Readers Name
	If doc.DocTopic(0) = "Project Management" And doc.SubTopic(0) = "Financials" Then
		If doc.HasItem("DocReaders") Then
			Call doc.ReplaceItemValue("DocReaders",  "[FinanceViewer]")
			Set item = doc.GetFirstItem("DocReaders")
			item.IsReaders = True
			item.IsSummary = True
		Else
			Set item = New NotesItem( doc, "DocReaders" , "[FinanceViewer]" , READERS )   
			Item.IsSummary = True
		End If 

	If doc.SubTopic(0) = "Rate files" And doc.RateDistribution(0) = "Stage 1" Then
		If doc.HasItem("DocReaders") Then
			Call doc.ReplaceItemValue("DocReaders",  "[PricingStage1]")
			Set item = doc.GetFirstItem("DocReaders")
			item.IsReaders = True
			item.IsSummary = True
		Else
			Set item = New NotesItem( doc, "DocReaders" , "[PricingStage1]" , READERS )   
			Item.IsSummary = True
		End If 

	Else
		If doc.HasItem("DocReaders") Then
			Call doc.ReplaceItemValue("DocReaders",  "[All]")
			Set item = doc.GetFirstItem("DocReaders")
			item.IsReaders = True
			item.IsSummary = True
		Else
			Set item = New NotesItem( doc, "DocReaders" , "[All]" , READERS )   
			Item.IsSummary = True
		End If
End If 
End If

======================

Open in new window

0
AliciaVee
Asked:
AliciaVee
1 Solution
 
CRAKCommented:
What about this bit?
Dim ReadRole As String
	
	' Determine Readers Name 
	If doc.DocTopic(0) = "Project Management" And doc.SubTopic(0) = "Financials" Then 
		ReadRole = "[FinanceViewer]"
	Elseif doc.SubTopic(0) = "Rate files" And doc.RateDistribution(0) = "Stage 1" Then 
		ReadRole = "[PricingStage1]"
	Else 
		ReadRole = "[All]"
	End If
	
	' Set Readers Name
	Set item = doc.ReplaceItemValue("DocReaders",  ReadRole)
	item.IsReaders = True
	item.IsSummary = True

Open in new window

0
 
Sjef BosmanGroupware ConsultantCommented:
Or is it this:

        ReadRole = "[All]"
        If doc.DocTopic(0) = "Project Management" Then
            If doc.SubTopic(0) = "Financials" Then
                      ReadRole = "[FinanceViewer]"
              Elseif doc.SubTopic(0) = "Rate files" And doc.RateDistribution(0) = "Stage 1" Then
                      ReadRole = "[PricingStage1]"
            End If
        End If

The logic already seems quite complex to me. Could a state machine help you maybe??
0
 
AliciaVeeAuthor Commented:
CRAK -- excellent. Worked great -- and I even added another elseif to capture the PricingStage2 role -- if one is needed (not sure yet).

Thanks!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now