Using custom code in SSRS PDF rendering
Hi,
I have a written some custom code ( a simple function to maintain a counter ) in SSRS Report properties.
Everything works fine when I render the report in Report Viewer, but the custom code is not recognized when I render the report to PDF.
What is wrong with my code?
There is no error reported. The custom code is just getting skipped when I render to PDF.
My custom code is as follows..
Public Shared Dim iCounter AS Integer = 1
Public Function IncrementCounter(SomeValue As Boolean) As Boolean
iCounter = iCounter + 1
Return SomeValue
End Function
Public Function GetCounter() As Integer
Return iCounter
End Function
and my call to the custom code is..
=code.GetCounter()
Hi ha_emp,
From your description, it seems that custom code work well when you preview the report. While it would be skipped when the report is exported to PDF. After testing the custom code in my environment,I find that the custom code will run again when exporting
the report, so when we run the report on Report Server and export it to PDF, the custom code will be run twice, the value will be counted twice.
Based on my research, I find that we can delete the “Shared” in the first row of the custom code to fix this issue. Then the custom code will works well on Report Server.
If there are any misunderstanding, please elaborate the issue for further investigation.
Thanks,
Katherine Xiong
We
are trying to better understand customer views on social support experience, so your participation in this
interview project would be greatly appreciated if you have time.
Thanks for helping make community forums a great place.
Similar Messages
-
hi sir
i am fresher,
i need breif about custom code in ssrs,
what is cutom code,
why it is used,
what is the perpose of this code...
help me to learn.
thank you.custom code is used mostly for implementing functionalities which cannot be done using standard features available in SSRS. Custom code should be written using .NET language. If you want to share same code across multiple reports you should make it into
a dll and reference it from all the required reports.
More details here
https://msdn.microsoft.com/en-us/library/ms156028.aspx
https://msdn.microsoft.com/en-us/library/ms159238.aspx
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Hi,
I am trying to write Custom Code in SSRS for Age Calculation for two requirements in the same report,But report is giving error #Error in expression with my below code.
whole logic is same for both but only two lines are different,Do i need create two functions or can i use them in one function.Please guide me.
1)Age in Years (Ex: 4)
2) Age in Years + months (ex: 3 Years 6 months)
My SSRS Custom Code:
Public Shared Dim Years as Integer
Public Shared Dim Months as Integer
Public Shared Dim Days as Integer
Public Shared Dim Age as Integer
Public Shared Function CalAge(ByVal D1 As Datetime,ByVal D2 As Datetime ) As Integer
Years=Year(D1)-Year(D2)
Months=Month(D1)-Month(D2)
Days=Day(D1)-Day(D2)
If Days < 0 then
Months=Months-1
End if
If Months < 0 then
Years=Years-1
End if
If Months < 0 then
Months=Months+12
End If
Return Years
If Months=1 then
Age=Years+" Years " + Months + "Month"
else
Age=Years+" Years " + Months + "Months"
End If
Return Age
End Functionhi Guys,
I have finally changed my custom code to below :
Public Shared Dim Years as Integer
Public Shared Dim Months as Integer
Public Shared Dim Days as Integer
Public Shared Function CalAge(ByVal D1 As Datetime,ByVal D2 As Datetime ) As Integer
Days=DatePart(DateInterval.Day,D1)-DatePart(DateInterval.Day,D2)
Months=DatePart(DateInterval.Month,D1)-DatePart(DateInterval.Month,D2)
Years=DatePart(DateInterval.Year,D1)-DatePart(DateInterval.Year,D2)
If Days < 0 then
Months=Months-1
End If
If Months < 0 then
Years=Years-1
End If
If Months < 0 then
Months=Months+12
End If
Return Years
End Function
Public Shared Function CalMon(ByVal D3 As Datetime,ByVal D4 As Datetime ) As Integer
Days=DatePart(DateInterval.Day,D3)-DatePart(DateInterval.Day,D4)
Months=DatePart(DateInterval.Month,D3)-DatePart(DateInterval.Month,D4)
Years=DatePart(DateInterval.Year,D3)-DatePart(DateInterval.Year,D4)
If Days < 0 then
Months=Months-1
End If
If Months < 0 then
Years=Years-1
End If
If Months < 0 then
Months=Months+12
End If
Return Months
End Function
and using expression in SSRS fo display like this :
=IIF((Code.CalMon(Parameters!AgeCalcDate.Value,Fields!StudentBirthDate.Value))=1,Code.CalAge(Parameters!AgeCalcDate.Value,Fields!StudentBirthDate.Value) & " Years " & Code.CalMon(Parameters!AgeCalcDate.Value,Fields!StudentBirthDate.Value)
& " Month ",
Code.CalAge(Parameters!AgeCalcDate.Value,Fields!StudentBirthDate.Value) & " Years " & Code.CalMon(Parameters!AgeCalcDate.Value,Fields!StudentBirthDate.Value) & " Months ")
got the correct solution. -
How to query a dataset using custom code in report builder 3.0
Hi,
Can anyone please suggest whether it is possible to query a dataset by using custom code in report builder 3.0.
Thanks in advance.Hi Purbasha,
please see below similar thread:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/9af8f39a-9dc5-49ab-91af-2f64198c8477/ssrs-2008-custom-code-for-database-query
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/440ff5de-1c21-47de-95d8-e4212d6cef6d/dataset-in-custom-code-in-sql-server-reporting-services?forum=sqlreportingservices
swallow -
Update Power View reports properties using custom code
Is there any way to update power view reports uploaded in SharePoint 2013 shared data source link using custom code?
Best Regards,
Sameer Salunke
MCTS-Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.Someone out here must have an answer???? I know that SharePoint 2013 saves the view created in Power View therefore the metadata must be accessible somehow? Can someone explain
how to find that metadata in the SQL tables maybe? I would be surprised to find out I am the only one who needs this?
Ken Craig -
File upload in KM using custom code
Hi All,
We do keep on getting requests to frequently upload versions of file in KM for our users, Is there a way where a customised iview can be developed to pick up a file from desktop and upload it in KM ? I think this can be done using Webdynpro Abap or Webdynpro Java not very sure .
Please guide me with pre-requisites and steps as I am new to such kind of development in portal.
Regards,
Jalpa ShuklaHi Jalpa Shukla,
Not sure what you mean by "getting requests to frequently upload versions of file". If you are trying to write some custom code through which you can upload a file in KM (and maintain the document versions). Check [this|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/3095f14c-29c5-2b10-f69e-edcb6f0f1367?QuickLink=index&overridelayout=true] link.
Hope it helps!
Thanks, Ansar. -
Custom code in SSRS gives error when uploaded to report in CRM online
Hi All;
Below is my custom code
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
ct += 1
Next
If (ct = 0) Then return 0 else return suma
End Function
and this code is used in
=Code.SumLookup(LookupSet(Fields!new_mainprogrammeid.Value & "," &
Fields!new_subprogrammeid.Value & "," &
Fields!new_outputs.Value & "," &
Fields!new_claimmonthid.Value,
Fields!new_mainprogrammeid.Value & "," &
Fields!new_subprogrammeid.Value & "," &
Fields!new_outputs.Value & "," &
Fields!new_claimmonthid.Value,
Fields!new_fte.Value, "JobOutcome"))
when this code is uploaded in CRM online report it gives an error
below is the error from the log file
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: An error occurred while trying to add the report to Microsoft Dynamics CRM. Try adding the report again. If this problem persists, contact your system administrator.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147188072</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>An error occurred while trying to add the report to Microsoft Dynamics CRM. Try adding the report again. If this problem persists, contact your system administrator.</Message>
<Timestamp>2014-10-07T14:21:25.5823821Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>
but when i remove the custom code and upload the lookup as below i dont get any error
=(LookupSet(Fields!new_mainprogrammeid.Value & "," &
Fields!new_subprogrammeid.Value & "," &
Fields!new_outputs.Value & "," &
Fields!new_claimmonthid.Value,
Fields!new_mainprogrammeid.Value & "," &
Fields!new_subprogrammeid.Value & "," &
Fields!new_outputs.Value & "," &
Fields!new_claimmonthid.Value,
Fields!new_fte.Value, "JobOutcome"))
I need to calculate the sum of fte hence needed the custom code
Any help on this much appreciated
Thanks
Pradnya07Hi Simran08,
According to your description, you fail to add your report to CRM due to the custom code. Right?
In this scenario, based on my knowledge, I find two issues in your custom code.
You pass the array Items as argument to the function. This array is from the LookupSet() function. However, it returns an concatenated string with commas. When you convert it into decimal, it will throw error.
In your For Each loop part, we should follow the format below:
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]
It seems you miss Item after Next.
If you still have any question, please feel free to ask.
Best Regards,
Simon Hou -
Creating "Payables Account Transaction" using custom code
Hi Gurus,
I need a help. I have a requirement that I have to create "Payables Account Transaction" using custom PL/SQL code. Kindly could you advise me as to which API or Package should i use to get this done. Currently I am in 11.5.10.2.
Pls help me on this.
Thanks,
GenooHi Genoo,
As mentioned I would reverse the standard journals coming from Payables, that way you can still see what the original journals were and drill back using them. So you don't do anything in the subledger.
Alternatively if you wanted to get more risky, when you run the Payables transfer to GL, you could choose not to submit journal import and then you could manipulate the AP Journal records while they are still in the GL_INTERFACE (as they also go through that table) prior to going to GL, then you could do whatever you want - and if you don't delete them (but update / copy them) they will still retain the drilldown links back to AP.
Regards,
Gareth -
Create lead via reference to campaign using custom code
I'm looking for an easy way via custom code to create a lead transaction and include a reference to a campaign object in my system. I'm having no luck with the XIF doc flow segment for the lead creation and would like to look for other methods to update this link.
Any suggestiosn on how to code this would be great. Yes I know that I could do ELM, but then I would need to rewrite my entire program, my leads create properly minus the campaign link.
As always help will be acknowledge and correct answers given here, will be put in the CRM wiki for future reference.
Thank you,
StephenOkay this actually will work via XIF adapter, the trick was proper settings of the related type attribute. When SAP inserts new doc flow for relations to campaigns it is done via "space" option. The LV_GUID needs to be GUID of the campaign in question.
LS_DOC_FLOW-RELATION_TYPE = 'VONA'.
LS_DOC_FLOW-RELOBJ_ROLETYPE = 'VORGAENGER'. "Role A
LS_DOC_FLOW-RELOBJ_OBJKEY = LV_GUID.
LS_DOC_FLOW-RELOBJ_TYPE = 'BUS2010020'.
LS_DOC_FLOW-OBJECT_TASK = 'I'.
LS_DOC_FLOW-RELATION_TYPE_ATTR = space.
LS_DOC_FLOW-INPUT_FIELDS-RELOBJ_ROLETYPE = 'X'.
LS_DOC_FLOW-INPUT_FIELDS-RELATION_TYPE = 'X'.
LS_DOC_FLOW-INPUT_FIELDS-RELOBJ_OBJKEY = 'X'.
LS_DOC_FLOW-INPUT_FIELDS-RELOBJ_TYPE = 'X'.
LS_DOC_FLOW-INPUT_FIELDS-RELATION_TYPE_ATTR = 'X'.
INSERT LS_DOC_FLOW INTO TABLE LT_DOC_FLOW_XIF_DATA.
Yep this will need to end up in the wiki once my I'm finished up with the full program/conversion. I guess I will keep my title as "pied piper" of the XIF adapter for now.
Take care,
Stephen -
Displaying a Content Area using custom code
Hello list,
Is it possible to display the contents of
a content area as a custom portlet so that I
don't have to expose the content area as a
portlet and I can add custom formatting etc ?
Any tips ?
SanjayA number of SQL views are provided for retrieving information
from content areas. These views are documented in the PDK. For
folders, use the view WWSBR_ALL_FOLDERS.
Regards,
Jerry -
How to move to next record of the databank file using custom code
hi,
can someone please tell me how to move to next or the previous record the Databank file. i found a funtion setcurrentdatabankrecord(), but i am not able to use it.
thanks in advance...Hi,
I recently had the same problem, here's my solution:
"setCurrentDataBankRecord" is available only to External Program Control.
I used the VB of an empty Word2002 Document.
1. you have to reference the webAnlyst.exe in the object-catalogue
2. create a module via the menue
3. type in the code
This is the code I used - some of the code is just for control
Private Sub TestSetDBRec()
Dim pdtest As webanlst.ProgT
Set pdtest = New webanlst.ProgT
Dim currDBI, numRecsCurrDB As String
' Workspace öffnen
pdtest.play.OpenWorkspace "VBTest"
' Script öffnen
pdtest.play.openScript "BM2B_VK_Änderung"
' DB-Abfragen
numRecsCurrDB = CStr(pdtest.play.getDataBankSize)
currDBI = pdtest.play.currentDatabankIndex
pdtest.play.setCurrentDataBankRecord (2)
currDBI = pdtest.play.currentDatabankIndex
' jetzt das Script abspielen
pdtest.play.doScript "BM2B_VK_Änderung"
End Sub
This works! You can also looping through the database by getting the current value and set the value back increased by e.g. one
Hope it is helpful! -
We have always used custom excel and other PDF files how do we build an app for ipad
apart from the "mac" what else do I need as I only want 1 license of the resulting app and as it is an inhouse app paying a developer and getting volume license is too expensive. Or is all extras in the dev pack issued by Apple
it is only for myself to use in the business on a day to day basis
The app is to collect 5-6 types of data that currently we have to write down each time we do certain processes with work
current example new page new day so 300+ sheets per year with 1-3 lines of writing on
initials of employee - product made - added ingredients batch numbers 4-5 columns - total made
this type of capture should be ideal for ipad with scroll or number input and each day new form saves the planet as well
our only issue is we have all custom programs and equipment based round XP pro systems and cannot go to touchscreen windows 8 with any of our old custom software hence going to custom app as keyboards are not possible in our industry due to hygiene issues unless stainless and silicon coated at $700 each -
How to load a XML into Checkpoint in UFT API using custom code
I am automating a webservice using UFT-12. In which I am trying to load a xml into the checkpoint at run time. but I am not able to find out a way of doing it.Can any1 help me on this?
@piyu_sh_arm
Thank you for using HP Support Forum. I have brought your issue to the appropriate team within HP. They will likely request information from you in order to look up your case details or product serial number. Please look for a private message from an identified HP contact. Additionally, keep in mind not to publicly post ( serial numbers and case details).
If you are unfamiliar with the Forum's private messaging please click here to learn more.
Thank you,
Omar
I Work for HP -
How to dynamically set width of SSRS columns in custom code?
How can I change the width of a table column based on a parameter value using custom code in SSRS?
If the parameter value is "Excel", I'd like the width to be 2 inches. If the parameter value is "Standard", I'd like the width to be 1 inch.Hi mmx_pdx,
Based on my research, we can only type static values for the width size in report. In Reporting Services, it not supported to set the size of width based on an expression currently. This is by design.
Personally, I recommend you that submit this suggestion at
https://connect.microsoft.com/SQLServer/. If the suggestion mentioned by customers for many times, the product team may consider to add the feature in the next SQL Server version. Your feedback is valuable for us to improve our products and increase the
level of service provided.
Thanks for your understanding.
Regards,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Function MakeList(ByVal items As Object()) As String
If items Is Nothing Then
Return Nothing
END if
Dim builder As System.Text.StringBuilder =
New System.Text.StringBuilder()
builder.Append("<div>")
For Each item As Object In items
builder.Append("<div <ul>")
builder.Append(item)
builder.Append("</ul>")
Next
builder.Append("</div>")
Return builder.ToString()
End Function
Function Length(ByVal items as Object()) as Integer
If items is Nothing Then
Return 0
End If
Return items.Length
End FunctionHi Wintersbay,
According to your description, when you use the custom code in SSRS report, you got the error message.
To solve the problem, please refer to the custom code below:
Function MakeList(ByVal items As Object) As String
If items Is Nothing Then
Return Nothing
END if
Dim builder As System.Text.StringBuilder =
New System.Text.StringBuilder()
builder.Append("<div>")
For Each item As Object In items
builder.Append("<div <ul>")
builder.Append(item)
builder.Append("</ul>")
Next
builder.Append("</div>")
Return builder.ToString()
End Function
Function Length(ByVal items as Object) as Integer
If items is Nothing Then
Return 0
End If
Return items.Length
End Function
If you have any more questions, please feel free to ask.
Thanks,
Wendy Fu
Wendy Fu
TechNet Community Support
Maybe you are looking for
-
Adobe creative cloud stops downloading
why wont my adobe creative cloud download? when it is halfway it stops downloading
-
Since I got the latest update, I can no longer get my Upromise Toolbar.
Last week, I downloaded the latest update for Firefox. Since then, I cannot get my Upromise toolbar to show up. I have re-downloaded the toolbar, but it still won't show up.
-
Hyper-v 2012 R2 server core recommendations for single server setup
Hi All, Next weekend I will be installing a brand new Dell 720 server for a client of mine. I would like to hear some recommendations on how to install this hypervisor. Let me state that I have had some experience with virtualization technology in t
-
hi to all experts, i have a requirement of listing purchase orders created only on Sunday and Saturday,please help me out im struggling with is report from 2 days. any sample code will help
-
Load Balance Between Diff DB's or Instances??
Hello All, Based on the below TNS entry, my understanding is that since it has multiple listener addresses by default connect time failover is configured and as description says load balancing option is also enabled. But how would i know whether fail